sscanf - %li query

Rahul rah.v.ragh@gmail.com
Fri Jan 2 06:06:00 GMT 2009


Hello all,

Please help me with this example.
   #include <stdio.h>
   int main()
   {
            signed long v;
            printf("sizeof(long) = %d\n", sizeof(long));
            v = 0xFFFFFFFF;
            printf("v-li = %li;   v-lx = %lx\n", v, v);
            sscanf("0xFFFFFFFF","%li", &v);
            printf("v-li = %li;   v-lx = %lx\n", v, v);
            sscanf("0xFFFFFFFF","%lx", &v);
            printf("v-li = %li;   v-lx = %lx\n", v, v);
           return 0;
   }
Got the following output for the above code with gcc version 3.2.3.
    sizeof(long) = 4
    v-li = -1;   v-lx = ffffffff
    v-li = 2147483647;   v-lx = 7fffffff
    v-li = -1;   v-lx = ffffffff
Why are values different when "%li" is used with 'sscanf'. Am I
missing something here or can this be a bug?
Request your guidance if this is not the correct place to post this query.

Thanks,
Rahul



More information about the Gcc-help mailing list