Possible Duplicate:
Easiest way to get file's contents in C
My program reads files that span over many lines. I would like to hold the content of a file in a single string.
I don’t know the number of lines of my file before execution, however I have fixed a line size to MAX_LINE_LEN.
How can you do that?
The function
fread()doesn’t care about line breaks. The following code reads the contents ofinput_file_nameand saves them to the arrayfile_contents:You can only make a string of this array if
input_file_namecontains the\0character. If it does not, change the last three lines to: