How can I read a string from a text file until line break (besides using fgetc)?
How can I read a string from a text file until line break (besides using fgetc)?
fgets
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
fgets requires a buffer size. What is the maximum length of a single line of a text file (if there is such thing)?Originally Posted by Dave_Sinkula
Generally, whatever size you declare your input buffer to be.Originally Posted by Crilston
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
You could read the line until you reach '\0' with a while loop
and just read the line through.Code:while(line[index] != '/0')
That's pretty much the same as using fgetc().
If you don't know the size in advance, the best way to do it is to use fgetc().
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.