How to Skip a Line in C File Reading
Skip 3 lines from a file while storing into array
I'm doing an assignment for school and I'm stuck. From the following .txt file:
John
100
99
100
Julio
88.v
eighty.five
85
Johnathan
70
83.5
86
Julia
80.five
89.ix
93
I demand to skip the grades to shop only the names in the array ""string names[NAMES_SIZE]""
| |
Thank you in accelerate.
I tin can think of 2 simple means to practice it.
Manner i:
You read the file line past line using a counter starting at 0 and increment it by 1 later on the line was read.
If the counter is 0, iv, 8...it is a proper name and you use information technology.
Way two:
You read the file line past line and bank check if the line is a number. If information technology is not a number then it must be a name and you can use information technology.
I'g a beginner and my lawmaking knowledge is very poor, would y'all please prove your caption in code, if you used the same variables names equally I did would be really helpful. Cheers
Concluding edited on
A suggestion: since you have to store all the values in your two arrays:
| |
then there'southward no demand to skip annihilation. Just read all of the data in the social club in which it appears in the file.
In outcome, something similar this:
| |
The while loop condition is worth a closer look, first it checks that count is not bigger than the array size. And then it attempts to read a name. If that succeeds, the body of the loop will then exist executed. But y'all however need to check the status before incrementing the count - if something goes incorrect, you lot demand to know how far it got before failure. After the loop completes, the count
will contain the number of complete sets of data
Note besides, where I put grade1
etc, yous need to put the other assortment in there instead.
Last edited on
Every bit already suggested, one of many possible variants:
| |
Please enter the file name. skip_items.txt John Julio Johnathan Julia Program concluded with leave code: 0
Topic archived. No new replies allowed.
Source: http://www.cplusplus.com/forum/beginner/219155/
Postar um comentário for "How to Skip a Line in C File Reading"