Reputation: 3
How can I skip a value and go to the next one in fscanf()
? For example I have the following data in my input file:
11112222
3.95
4
22.5
What I should do in order to scan the second value? (I want to skip 11112222 to scan 3.95)
And one more thing: if I want to fscanf()
a specific data type, how can I do that? (Ex: I want to scan double
value and skip the int
value.)
Upvotes: 0
Views: 223
Reputation: 126378
You can use a *
modifier to scan a value and throw it away rather than storing it. For example:
if (scanf("%*d%lf", &var) != 1)
…process input error…
will read the first two lines of your input file and store the value from the second into the double variable var
Upvotes: 4
Reputation: 744
int fun() {
int unusedvar;
float value;
FILE *fp=fopen("yourfilename","r");
fscanf(fp,"%d%f",&unusedvar,&value);
return 0;
}
Aint that simple?
Upvotes: 0