tags:

views:

63

answers:

3

hi. i have this code (im working with big files support in ansi c)

unsigned long int tmp,final
final=1231123123123213
tmp=final;
    printf("%llu %llu  \n",final,tmp);
    printf("%llu  \n ",tmp);

it prints

1231123123123213 0
1231123123123213

i dont get it

+2  A: 

Because you're using the wrong type.

unsigned long long int tmp, final;

The compiler should complain about the numeric constant (the literal 1231123123123213) not fitting a long int. It gets truncated. Plus, %llu is for printing long long ints, not long ints ;).

mingos
+1 because I can't give you karma for trying the other answer any other way. Besides, this answer is correct ;-)
RBerteig
A: 

You need %lu not %llu.

Alexander Rafferty
why did you downvote?
Alexander Rafferty
It wasn't me, but I guess it might have been because using the long int formatter would not fix the problem at all, as the numeric literal is still longer that a long int ;)
mingos
Matt Kane
+5  A: 

Format specifier used with unsigned long int is %lu. You are using %llu, which is format specifier for unsigned long long int. The behavior of your code is undefined.

You need to decide what it is you are trying to do. Either use the correct format specifier (to match the type), or use the right type (to match the format specifier).

AndreyT
nice answer. ok i was trying to work with long int insted of long long int (and my code got weirds answers) i switch to long long int and now its doing his job, thanks. i was using long int to get the values of ftello64
Freaktor