Question: CS 539 Lab Exercise: read file w getc Create the readFile function: char * readFile(const char * fileName); readFile's job is to try to open

CS 539 Lab Exercise: read file w getc

Create the readFile function:

char * readFile(const char * fileName);

readFile's job is to

try to open fileName for reading in text mode, c&d on failure

Using getc, read all the chars of the file into a DA array of chars.

(awc that the file has at least one char)

(awc that the only error we'll encounter trying to read a char from the

file is EOF)

(awc that each line in the file is terminated by a .)

(awc that the file contains no null chars.)

Each char in the file gets copied to one char in the DA array, including

's, then terminated with a null char.

return the DA array

close the file

Have readFile read the file named "input.txt".

Output the contents of the file.

Deallocate the DA array

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!