What is the printf conversion character for a long long? And the one for a long double? I just noticed that %d and %x.f (x number of decimal places) don't work with long longs and long doubles.
Thanks.
What is the printf conversion character for a long long? And the one for a long double? I just noticed that %d and %x.f (x number of decimal places) don't work with long longs and long doubles.
Thanks.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
ll (two lowercase L) for a long long int, L for a long double (in standard C99 at any rate).
I don't understand. I am trying to output a long double using printf. I tried %L, %.0L, %Lf, %.0Lf, %L.0f, %.0fL, and none of them work!?!?!
Last edited by samus250; 04-13-2008 at 06:54 PM. Reason: typos
Using minGW on windows? See here;
http://coding.derkeiler.com/Archive/.../msg04086.html
Yup, that's me, MinGW on Windows. But I still didn't get the conversion character I need for the printf function from that post.
[edit] Or is it simply not possible using MinGW?
Last edited by samus250; 04-13-2008 at 07:14 PM.
That's because there isn't one. The MS runtime doesn't support the 10-byte long double that gcc uses. To print it, cast it to a double and hope that it's within range.
http://www.mingw.org/MinGWiki/index.php/long%20double
Or I suppose you could write your own printf-like function just for long doubles....
Just for you (and for me, since I have MinGW on Windows, too), this appears to work -- although I hacked it together in the last ten minutes so you never know:
Use at your own peril.Code:char *printf_ld(long double arg, char answer[15]) { /* For my own sake: scientific notation with six digits */ double mantissa, exponent, lg; lg = log10l(fabs(arg)); exponent = floor(lg); mantissa = pow(10, lg-exponent); mantissa = copysign(mantissa, arg); sprintf(answer, "%.6fe%+04g", mantissa, exponent); return answer; }
Cool, thanks a lot! I'll give a look at that.