Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please using C, not C+ or C++, Thanks. Files to submit: read_lines.c, read_lines.h Time it took Matthew to Complete: 10 mins Requriements Program must compile

Please using C, not C+ or C++, Thanks.

Files to submit: read_lines.c, read_lines.h

Time it took Matthew to Complete: 10 mins

Requriements

Program must compile with both -Wall and -Werror options enabled

Submit only the files requested

Use doubles to store real numbers

Print all doubles to 2 decimal points unless stated otherwise

Restrictions

No global variables may be used

Your main function may only declare variables and call other functions

Description

The programming language Python has some really nice functions for dealing with files. One of them is called readlines and it reads the lines of the files into an array. For this projcet you will be implementing readlines in C.

Additional Details

For this assignment you will be creating a function and not an entire program.

The function your create should have the following signature:

void read_lines(FILE* fp, char*** lines, int* num_lines) 

This function should read all of the lines in the file pointed to by fp and

Set each row of lines to contain one line of the file

Set num_lines to be equal to the number of lines that were in the file

If the file is empty lines should be set to NULL and num_lines to 0

You should only submit read_lines.c and read_lines.h

I will provide main.c and the Makefile

Your code must compile using this Makefile and main.c

You cannot edit main.c

While you only have to write read_lines you can write as many other functions as you want

Hints

I highly recommend making more functions than just read_lines for solving this problem.

For example a function that reads a single line from the file

Examples

User input has been underlined to help you differentiate what is user input and what is program output.

Example 1

./read_lines.out Makefile

read_lines.out: read_lines.o main.o gcc -g -Wall -Werror -o read_lines.out read_lines.o main.o main.o: main.c read_lines.h gcc -g -Wall -Werror -c -o main.o main.c read_lines.o: read_lines.c read_lines.c gcc -g -Wall -Werror -c -o read_lines.o read_lines.c clean: rm -f *.out *.o

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

More Books

Students also viewed these Databases questions

Question

The ping program operates at which layer of the OSI model?

Answered: 1 week ago