Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to read a line from a file

Status
Not open for further replies.

d1trupinoy

Technical User
Dec 11, 2001
14
US
I am a newbie so please be specific. How can I read in 1 line at a time from a file.txt. Example:

-blahbla-,my name is blah,ok' I amhere
'omally,-myname 'isomally,oneword
......

I will use strtkn to parse each line by comma. I need to figure out how to read in one line first though before I can parse it. One line is a whole string before a carriage return
 
Code:
FILE* fs;
char linebuf[1024];

fs = fopen("file.txt","r");
if (fs != NULL) {
  while (fgets(linebuf,1024,fs) != NULL) {
    /* do something */
  }
}


I REALLY hope that helps.
Will
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top