home *** CD-ROM | disk | FTP | other *** search
- /* demonstrates sscanf() (adapted from K&R's C Prog. Lang., p. 149) */
-
- main() /* sscanf.c -- illustrates sscanf() */
- {
- char *input;
- int i;
- float x;
- char name[50];
-
- input = "25 54.32E-1 Thompson";
- sscanf(input,"%d %f %s", &i, &x, name);
- printf("%d %f %s ", i, x, name);
- input = "56789 0123 45a72";
- sscanf(input,"%2d %f %*d %2s", &i, &x, name);
- printf("%d %f %s\n", i, x, name);
- puts("Correct answer: 25 5.432000 Thompson 56 789.000000 45");
- }