Reputation: 311
I am reading strings in from a data file in C using fscanf()
using a loop that goes until EOF
. The data file contains strings separated by any white space. As the strings are read in with fscanf()
they will be checked for any invalid information. I need to keep track of the line numbers that an item is on so that if an invalid item is detected the line number of that item will be displayed. Like I said though, the data file is not just one string per line. Is there anything more elegant than reading in everything up to a new line, splitting that into individual strings, and checking those strings? Can I determine the line number where the file pointer is currently pointing?
Upvotes: 0
Views: 534
Reputation: 33273
There is no line number counter in the C I/O libraries. You need to keep track of the line number yourself.
I suggest that you read one line at a time using fgets
, incrementing your line number counter each time, and then read items from that string using sscanf
.
Upvotes: 3