home *** CD-ROM | disk | FTP | other *** search
- /*
- demonstrates fscanf() (adapted from K&R p. 149)
-
- Note that file fscanf.tst contains (only):
-
- 25 54.32E-1 Thompson
- 56789 0123 45a72
- */
-
- main() /* fscanf.c -- illustrates use of fscanf() */
- {
- FILE *input;
- int i;
- float x;
- char name[50];
-
- if((input = fopen("fscanf.tst","r")) == NULL) {
- puts("Can't open fscanf.tst");
- exit();
- }
- fscanf(input,"%d %f %s", &i, &x, name);
- printf("%18d %f %s ", i, x, name);
- fscanf(input,"%2d %f %*d %2s", &i, &x, name);
- printf("%d %f %s\n", i, x, name);
- puts("Correct answer: 25 5.432000 Thompsom 56 789.000000 45");
- }