FILE *fin = fopen("figura.in", "r");
if(fscanf(fin, "%d %d %d %d", &int[0], &int[1], &int[2], &int[3]) == 1) {
printf("%d\t%d\t%d\t%d\n", int[0], int[1], int[2], int[3]);
} else {
printf("failed to read integer.\n");
}
I get failed to read integer. The file is okay, it consists 4 integers. What is wrong?
You should be checking to see if
fscanf
returns 4, the number of inputs in your format string:From the man page: