
(novice) I'm Having trouble scanf'ing a double ?
Quote:
>Just when I thought I understood C...
>I am having trouble using doubles. My code looks something like this:
>double mean;
>...
>scanf ("%f", &mean);
>...
>When I put my de{*filter*} on the line just after the scanf (which should have just
>read the number 1) mean is usually something ridiculously small (like 3.3123
>E-38 or somesuch). If I declare mean to be a float, however, it seems to
>work. But, I think I will need the extra precision.
>Are there some special contortions I need to go through to read this in ?
>I can't find anything about scanning doubles in any of my C books.
>Thanks, I was embarassed to ask,
>Terry
Dear Terry,
Y'all didn't say which compiler you were using, but I'm assuming
that it behaves like the three I've used: doubles are bigger than floats.
That being the case, you have to tell scanf how big a buffer is available
for the read. So the long-float format %lf might do it.
Now _my_ question: what is the format for reading in a tenbyte (long
double) in Turbo C++? Seems like a shame not to play with variables
which can store such grandmungous values :)....