i want to write a program that reads a text file containing an unspecified number of lines of unspecified length. the hardest part is to allocate memory. should i just allocate memory with malloc to char array that i think should be enough or what? what's the best way to do it...
Read a line into a buffer, then malloc some space and copy it into it. Lather, rinse, repeat.
Something like a linked list would work well for holding the lines for you.
Use the system file functions of your compiler to get the file size, allocate a buffer for the entire file, and read it all in.
Otherwise, you'll have to know at least how big a buffer you can use that is larger than any line in the file.
Third way is to read the file thru once finding out how long the longest line is, allocate that buffer, and start reading again.