5 char * str = "10.5 15 hello";
9 sscanf(str,"%f %d %s",&fval,&d,buf);
10 printf("got -> %g %d %s\n",fval,d,buf);
21 printf("Input a char set:\n");
22 scanf("%[abcdefghijklmnopqrstuvwzyz] %*[^\n]",buf);
23 printf("got -> %s\n",buf);
26 printf("Input a float:\n");
28 printf("got -> %f\n",fval);
30 printf("Input int and string:\n");
31 scanf("%d %[abcdefghijklmno]", &i, buf);
32 printf("got -> %d [%s]\n",i, buf);
34 printf("Input long:\n");
36 printf("got -> %ld\n",lval);
38 printf("Input an int with more than 2 digits:\n");
39 scanf("%2d %d ", &i, &k);
40 printf("got -> %d %d\n",i,k);
49 int count; float quant; char units[21], item[21];
51 fp = fopen("/tmp/xxeicxx","w+");
52 fputs("2 quarts of oil\n"
53 "-12.8 degrees Celsius\n"
59 fseek(fp,0L,SEEK_SET);
62 units[0] = item[0] ='\0';
63 count = fscanf(fp,"%f%20s of %20s",&quant, units, item);
65 fprintf(stdout,"count = [%d] quant = [%g] units = [%s] item = [%s]\n",
66 count,quant,units,item);