I am currently developing a simple C application. It takes a single file as a command line argument, which is formatted like:
1,2,3
4,5,6
7,8,9
etc.
However, for whatever reason, fscanf
never scans the numbers! Here is an example:
#include <stdio.h>
int main(int argc, char **argv) {
FILE *file = fopen(*argv, "r");
int i1, i2, i3;
while (fscanf(file, "%d,%d,%d", &i1, &i2, &i3) == 3) {
printf("Doing stuff with %d, %d, and %d...\n", i1, i2, i3);
}
fclose(file);
return 0;
}
If you run it with the filename as an argument, then it immediately exits, due to fscanf
returning 0. I've tried several variations of this, to no avail. How do I make fscanf
read the numbers correctly?