/* File: scan7.c using fscanf */ #include main() { int a, b, c, r ; FILE *ifile, *ofile ; ifile = fopen("test", "r") ; ofile = fopen("output", "w") ; if ( (ifile == NULL) || (ofile == NULL)) { fprintf(stderr, "Could not open file\n") ; abort() ; } while (1) { r = fscanf(ifile, "%d %d %d", &a, &b, &c) ; if (r < 0) break ; /* EOF encountered */ fprintf(ofile, "a = %d, b = %d, c = %d\n", a, b, c) ; } fclose(ofile) ; fclose(ifile) ; }