Alright, I have a program I am working on and I want it so it opens a file, and it grabs the first word from each line. I am using a while statement to do this, but I can't figure out how to tell the while statement to go to the next line, it will just grab the next word of the sentence. Any suggestions?
file Input question
Collapse
X
-
Originally posted by daduke40Alright, I have a program I am working on and I want it so it opens a file, and it grabs the first word from each line. I am using a while statement to do this, but I can't figure out how to tell the while statement to go to the next line, it will just grab the next word of the sentence. Any suggestions?
If you read using fgets then it will read a full line.
After reading it use sscanf to get the first word from the read string.
If you do a fgets again it will read the next line in the file and do the process again
Raghuram
Comment