(novice) I'm Having trouble scanf'ing a double ? 
Author Message
 (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


You need format %lf for doubles in scanf, instead of %f.


Sun, 11 Feb 1996 06:09:18 GMT  
 (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 :)....


Sun, 11 Feb 1996 03:37:32 GMT  
 (novice) I'm Having trouble scanf'ing a double ?

Quote:
>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 :)....

It's a shame to complain before RTFM :-)
According to the standard, it's "%Lf".

Dan
--
Dan Pop
Tel:   +41.22.767.2335

Mail:  CERN - PPE, Bat. 21 1-023, CH-1211 Geneve 23, Switzerland



Sun, 11 Feb 1996 20:42:47 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Q!!'scanf'ing strings with char**s

2. trouble with realloc'ing array of char *'s

3. Q:Frequent malloc'ing and free'ing

4. DAO code samples - found some but having problems with Release'ing objects

5. ANSI C: printf'ing long doubles ?

6. AND'ing doubles

7. Troubles using C's scanf Function

8. scanf doesn't work for variables of type double

9. how to prevent 'free'-ing memory twice

10. read()'ing from a child's piped stdout

11. Quickie on free()'ing malloc()'d mem

12. typedef'ing iterators in MSVC's STL (not the HP STL)

 

 
Powered by phpBB® Forum Software