file Input question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • daduke40
    New Member
    • Mar 2008
    • 9

    file Input question

    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?
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Originally posted by daduke40
    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?

    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

    Working...