Code:
$ cat foo.c
#include <stdio.h>
int main()
{
int v1, v2, v3;
char line[BUFSIZ];
FILE *file = fopen("foo.txt", "r");
if (file != NULL)
{
/* or other suitable maximum line size */
while (fgets(line, sizeof line, file) != NULL)
{
if (sscanf(line, "%d %d %d", &v1, &v2, &v3) == 3)
{
printf("V3 = %d %d %d\n", v1, v2, v3);
} else if (sscanf(line, "%d %d", &v1, &v2) == 2) {
printf("V2 = %d %d\n", v1, v2); //!! WAS foo.c:16:24: warning: format ?%d? expects a matching ?int? argument [-Wformat=]
} else if (sscanf(line, "%d", &v1) == 1) {
printf("V1 = %d\n", v1);
}
}
}
else
{
printf("error file openning");
}
return 0;
}
$ cat foo.txt
60
4 1 4
607
4 5 6
3 1
4 2
$ gcc foo.c
$ ./a.out
V1 = 60
V3 = 4 1 4
V1 = 607
V3 = 4 5 6
V2 = 3 1
V2 = 4 2