Thread: Reading text files form a certain line???

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    35

    Question Reading text files form a certain line???

    how do you read a text file from justa certain line???

    Ex.

    Question:
    [question here]

    Answer:
    [answer here]


    How do I read just the answer line??

    Thanks in advance

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    You could read the file in line by line, loading each line into a temp string variable, then use strcmp to check for "Answer:". Once you find it, read in the next line and populate your answer variable with that data.

  3. #3
    Unregistered
    Guest
    If your file is of standard field widths, then using fseek() might work too. If, as in most files, that isn't the case, then it's hunting time, like jdinger recommends.

  4. #4
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    if those don't work i think ignore() could help

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    35
    could somebody give me an example on how to do it with strcpy()

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Detecting end of LINE in text files
    By kiknewbie in forum C Programming
    Replies: 6
    Last Post: 12-09-2008, 09:34 AM
  2. Reading Sequential Text Files
    By Acolyte in forum C Programming
    Replies: 1
    Last Post: 11-22-2007, 06:33 PM
  3. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  4. Reading a line from a text file Please help
    By Blizzarddog in forum C++ Programming
    Replies: 7
    Last Post: 05-22-2003, 12:35 PM
  5. text files & notepad problem
    By bigtamscot in forum C Programming
    Replies: 2
    Last Post: 05-01-2003, 04:41 PM