Skipping data with fscanf?
-
Hello, I have 80 lines in a text file with 30 values each line separated by a white space (some are ints, doubles and another strings). I have made a routine with fscanf() to read each line and store the values I need. But I only need 7 of the 30 values to store them in an array, so , for instance, I want to store the first data, and the second and third, then skip the next 4 values, store the next and so on. Is there a way to skip entries with fscanf function? Thank you.
-
Hello, I have 80 lines in a text file with 30 values each line separated by a white space (some are ints, doubles and another strings). I have made a routine with fscanf() to read each line and store the values I need. But I only need 7 of the 30 values to store them in an array, so , for instance, I want to store the first data, and the second and third, then skip the next 4 values, store the next and so on. Is there a way to skip entries with fscanf function? Thank you.
José Luis Sogorb wrote:
Is there a way to skip entries with fscanf function?
Oh yes. Simply read unwanted entries and then discard them. :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles] -
José Luis Sogorb wrote:
Is there a way to skip entries with fscanf function?
Oh yes. Simply read unwanted entries and then discard them. :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles]Yes, but I have to read the unwanted data and assign them a place to store them and then discard? There are 23 unwanted entries in each line, and there are 80 lines. This is what I dont want to do.
-
Yes, but I have to read the unwanted data and assign them a place to store them and then discard? There are 23 unwanted entries in each line, and there are 80 lines. This is what I dont want to do.
Well you haven't accumulate the garbage data. You may use a restricted set of variables (one for each different data type). :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles] -
Hello, I have 80 lines in a text file with 30 values each line separated by a white space (some are ints, doubles and another strings). I have made a routine with fscanf() to read each line and store the values I need. But I only need 7 of the 30 values to store them in an array, so , for instance, I want to store the first data, and the second and third, then skip the next 4 values, store the next and so on. Is there a way to skip entries with fscanf function? Thank you.
What's wrong with:
for (int x = 0; x < 80; x++)
{
fscanf(...);
if (some_condition)
{
// store in array
}
}"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne