MIDRANGE dot COM Mailing List Archive



Home » C400-L » January 2010

Re: Basic c question ==> atol



fixed

That's because %u is an "unsigned int" -- but you've used a (signed) long long instead of an unsigned int.

You need to use %lld (ll=long long, d=integer).

printf("num = %017lld\n", num);



On 1/29/2010 5:20 PM, hockchai Lim wrote:
ok. Now, I'm having problem converting this long long (64 bits) num back to
a string. I use %017u and it gives me a 00000000000000001. Why oh why
(can't c be a bit smarter :).

#include<string.h>
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
long long num;
char sBuf[30];

sprintf(sBuf, "6027461692 ");
num = atoll(sBuf);
printf("num = %017u\n", num); // the result num = 00000000000000001
exit(0);

}








Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2014 by MIDRANGE dot COM and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available here. If you have questions about this, please contact