hi i m new here!! now i got a problem ... I need a number not less than 13digits to assign to a variable. which data type should i use? i tried, (it might be wrong), "long long int " n still i got stuck!! help me out :(
Printable View
hi i m new here!! now i got a problem ... I need a number not less than 13digits to assign to a variable. which data type should i use? i tried, (it might be wrong), "long long int " n still i got stuck!! help me out :(
long long int will gladly handle numbers above 13 digits.
If it does not work, then show us your code and tell us what compiler you use.
Also try
printf("%d", sizeof(long long int));
and tell us what it prints.
a long long int contains 64bit so there is a number range of 9223372036854775807 to -9223372036854775807.
13 digits shouldn't be problem for long long int.
i m using gcc v4.1.2. and my piece of code is like this
<code>
long long int x= 13131313131313;
printf("%lld", x); // have also tried %ld.
</code>
And sizeof says 8.
Output: FFFFFFFFFFFFFFFFCode:#include <stdio.h>
int main()
{
unsigned long long ll = 0xFFFFFFFFFFFFFFFF;
printf("%llX\n", ll);
return 0;
}
Output: 18446744073709551615Code:#include <stdio.h>
int main()
{
unsigned long long ll = 0xFFFFFFFFFFFFFFFF;
printf("%llu\n", ll);
return 0;
}
I m so sorry for my stupidity!!! actually i am using lots of C compiler. I am currently using Dev-C++ 4.9.9.2 and i found out that it uses gcc v3.4.2 (mingw-special). (Sorry for losing your time). I tried your last code with this compiler and it prints 4294967295. help me out !!!!
That is becasue gcc-mingw uses an older C-library, so the printf format for long long is "%I64d" rather than "%lld".
--
Mats
Thank you very much!!! It works .... but may i know what is this "%I64d"... where can i learn more about format specifiers??? ;) Thank you!!
You may want to have a look here:
http://msdn.microsoft.com/en-us/libr...dc(VS.71).aspx
for example. Since gcc-mingw is using Microsoft's C library, the relevant generation of the MSDN documentation is what you need - I'm not sure if that's the exact right version, but it's at least 99% right.
--
Mats
Thanks again... a LOT Mr. Kernel hacker :)!! n many thanks to Elysia too!!! I m feeling much better now!!!
Strange that gcc would not support "standard" format specifiers? At least I believe they are standard.
But MS's printf DOES support llx or llu (the newer versions).
So if GCC uses an old library, then I blame GCC.
In C99, yes. HzTzr, compile your program with the -std=c99 option.Quote:
Originally Posted by Elysia
Only because the gcc-mingw maintainers hasn't produced a (stable) version of gcc-mingw for later versions than 3.4.x. But of course, it is still not GCC's fault for what is in a third party library, any more than it is the fault of a game that a particular implementation of OpenGL causes bad drawing on particular models of graphics card, right?
After all, the COMPILER can not fix the libraries it links to.
--
Mats