1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How do I get certain part of a file?

Discussion in 'C' started by Lokantis, Feb 19, 2009.

  1. Lokantis

    Lokantis New Member

    Joined:
    Oct 7, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    I am using C.
    Say I have a FILE datatype studentRecord in the following format " EntryIndex. lastname, firstname: score" for example "12. Simpson, Homer: 15". That is one record. Records are separated by space. Suppose the user enters number 12, how do I print out that exact record number 12? Logically I would think do somehing like
    go through the file character by character, if find combination like "studentNumber + "."" print out characters starting from that point until a third space character.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    Read the complete file into some structure which is equivalent to the data in the file and then either arrange them in a Linked List or even array and then traversing through it would help you get the needed record.

    The above solution would work assume you have few records and not thousands of them or else you may run out of memory
     

Share This Page