The first part of the lab is to write a program to read the complete contents of a file to a string.

computer science

Description

Part 1: Reading and Writing Complete Files (40 points) The first part of the lab is to write a program to read the complete contents of a file to a string. This code will be used in subsequent coding problems. You will need 3 functions: main(), read_file() and write_file(). The main function contains the driver code. The read_file() function reads the complete contents of a file to a string. The write_file() writes the complete contents of a string to a file. The read_file() will require:


Remember that when opening a file or allocating memory to check that the operation was successful. Both malloc() and fopen() return NULL when they fail. Also make sure to free all allocated memory when it is no longer needed. 


This function accepts a reference to size and a char array with the filename, and returns the allocated char array containing the contents of the file. Size is passed by reference to record the number of bytes in the file. Writing the file will require:  


Related Questions in computer science category