I am surprised that no one mentioned fscanf("%*d") - that the * sign tells fscanf to read the integer value, but ignore it (see the documentation here ). This allows you to do something like:
int numbers[MAX_NUMS]; int n = numbers_in_line(); for( i = 0; i < n; i++ ) if(i<n/2) fscanf("%d", &numbers[i]); else fscanf("%*d");
which seems clearer than just reading in the rest of the characters. If you knew n ahead of time, you could simply write:
scanf("%d %d %d %*d %*d %*d",&numbers[0],&numbers[1],&numbers[2]);
You did not ask about it directly, but if you read binary data, there is an additional way to skip the rest of the line. You can read what data you want and then calculate the location of the beginning of the next line (pointer arithmetic is indicated here) and use fseek to go to that location, which can save I / O time. Unfortunately, you cannot do this with ASCII data because numbers do not occupy uniform space.
source share