View Single Post
Join Date: Aug 2005
Posts: 15,392
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: read each line of file

 
0
  #2
Feb 5th, 2007
fgets() doesn't know the difference between characters, such as 'a', 'b', 'c' ... and numbers such as '1', '2', '3' ... '9'. In the file they are all just text. If you want to treat all those numbers as text, read the file line by line, then just use fgets() the normal way
  1. char line[80]
  2. FILE* fp = fopen("data.inp","r");
  3. while(fgets(line,1,sizeof(line),fp)
  4. {
  5. // do something
  6. }
  7. fclose(fp);

If you just want to add more lines to that file, then it isn't necessary to read it at all. Open the file for append and start writing -- new lines will be appended to the end of the existing lines.
Last edited by Ancient Dragon; Feb 5th, 2007 at 9:38 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote