Without lossing information?
Printable View
Without lossing information?
How do I get this to work?
returns a value of -555824486Code:#include <stdio.h>
int main()
{
char b[1000];
long long int i = 42393848474;
sprintf( b, "Formatted data: %d", i );
puts( b );
}
and larger numbers like long long int i = 88842393848474; shows 995330714
I have no idea what is happening here.
if I increase char b[] much more the compiler gives me the too big error
I need it to do the full spectrum of 18446744073709551615
Thanks
%d format is for int. Not for long long int. Use the wrong format specifier, and the result is undefined behaviour.
Look at Printf format strings - Cprogramming.com
Bye, Andreas
Thanks you guys.
add ll in %lld fixed the problem. Thankyou so much.
except that it dosen't work all the way to 18446744073709551615
I keep getting a negative number
what if I want to work with all positive numbers what would the range be then?
You can use "unsigned long long" in that case.
I tried that with 18446744073709551615 and it keeps giving me a negative number
Thanks for your help.
sprintf should also be changed to "%ulld" ( sorry, I forgot about that :D )
doing that gives me back a number that is 4294967295lldCode:#include <stdio.h>
int main()
{
char b[1000];
unsigned long long int i =18446744073709551615 ;
sprintf( b, "Formatted data: %ulld", i );
puts( b );
if (i&1) printf("is odd");
}
They mean %llu. Check "man 3 sprintf".
Thank you.