Josh Josh - 3 months ago 24
C Question

C - How to read in a certain line from a file

So I have a text file containing the following:

30.5 80.5 21
PERS Sarah 40 5 50
PERS Henry 30 10 20.6
PERS Martha 20 42 50.75
PERS John 35 10 80
PERS Jared 23 5 45.53

Without going into detail about what I need the program to do (I'll figure that out myself) 30.5 represents one price, 80.5 represents another price, and 21 represents a third price (all unique prices for different things)

The second line (the number 5) represents how many people are registering for a race.

The last 5 lines represent person information. PERS represents that an individual is registering, the name is obviously the person's name, the first number represents the person's age, the second number represents which race they're participating in (either a 5k run, 10k run, or 42k run) and the last number represents the amount of donations raised.

How can I scan a specific line of the file? For example, if I wanted to scan the information on John, how can I choose that I want to scan that line? It starts scanning from the first line of the file which I don't want. Hopefully this makes sense.


I'm afraid there isn't a way to just skip lines in a file - you'll just have to read it in starting from the first line. Plus you still need the information from the first lines anyway, right?