Back to index

glibc  2.9
scanf3.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 
00004 int
00005 main(int arc, char *argv[])
00006 {
00007   int n, res;
00008   unsigned int val;
00009   char s[] = "111";
00010 
00011   val = n = -1;
00012   res = sscanf(s, "%u %n", &val, &n);
00013   printf("Result of sscanf = %d\n", res);
00014   printf("Scanned format %%u = %u\n", val);
00015   printf("Possibly scanned format %%n = %d\n", n);
00016   if (n != 3 || val != 111 || res != 1)
00017     abort ();
00018 
00019   val = n = -1;
00020   res = sscanf(s, "%u%n", &val, &n);
00021   printf("Result of sscanf = %d\n", res);
00022   printf("Scanned format %%u = %u\n", val);
00023   printf("Possibly scanned format %%n = %d\n", n);
00024   if (n != 3 || val != 111 || res != 1)
00025     abort ();
00026 
00027   return 0;
00028 }