473,748 Members | 7,590 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

scanf double

hi gcc 3.4 says in a warning that %lf is not recognized as a scanf
format specifier is this right if so how to read in a double using scanf
thanks
Aug 7 '08 #1
6 9224
hi sorry this is c90 options recommended in this forum -W -Wall -ansi
-pedantic thanks

amarapreet wrote:
hi gcc 3.4 says in a warning that %lf is not recognized as a scanf
format specifier is this right if so how to read in a double using scanf
thanks
Aug 7 '08 #2
amarapreet said:
hi gcc 3.4 says in a warning that %lf is not recognized as a scanf
format specifier is this right if so how to read in a double using scanf
Whilst compilers are given licence to produce any diagnostic messages they
like, from a Quality-of-Implementation perspective it would be best if
they refrained from giving misleading information. %lf is the appropriate
format specifier for reading a value into a double via *scanf, and I can
confirm that gcc 2.95.3 gets this right. I would be very surprised to
learn that gcc 3.4 gets it wrong. Can anyone confirm this report?

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Aug 7 '08 #3
On Aug 7, 11:56*pm, amarapreet <a...@localhost .localdomainwro te:
hi gcc 3.4 says in a warning that %lf is not recognized as a scanf
format specifier is this right if so how to read in a double using scanf
thanks
Can you post an equivalent program that exhibits that compile time
diagnostic to be generated?
Could you also post the command line you use to invoke the compiler?
Thanks.
Aug 7 '08 #4
Pietro Cerutti wrote:
return (EXIT_SUCCESSc) ;
yep, now you tell me to post actual code....

--
Pietro Cerutti
Aug 7 '08 #5
"Richard Heathfield" <rj*@see.sig.in validwrote in message
news:le******** *************** *******@bt.com. ..
amarapreet said:
>hi gcc 3.4 says in a warning that %lf is not recognized as a scanf
format specifier is this right if so how to read in a double using scanf

Whilst compilers are given licence to produce any diagnostic messages they
like, from a Quality-of-Implementation perspective it would be best if
they refrained from giving misleading information. %lf is the appropriate
format specifier for reading a value into a double via *scanf, and I can
confirm that gcc 2.95.3 gets this right. I would be very surprised to
learn that gcc 3.4 gets it wrong. Can anyone confirm this report?
No problem with 3.2:
dcorbit@DCORBIT 64 /c/tmp
$ cat foo.c
#include <stdio.h>
#include <math.h>
#include <float.h>
#ifndef M_PI
#define M_PI 3.1415926535897 932384626433832 795028841971693 993751
#endif
#define deg2radian(x) ((M_PI/180) * (x))
int main(void)
{
double theta,
phi;
double thetahat[3],
phihat[3];
double r;
double rhat[3];
int converted;

oops:
printf("Enter theta, phi, r\n");
converted = scanf("%lf %lf %lf", &theta, &phi, &r);
if (converted != 3) goto oops;

theta = deg2radian(thet a);
phi = deg2radian(phi) ;
thetahat[0] = -sin(theta);
thetahat[1] = cos(theta);
thetahat[2] = 0;
phihat[0] = cos(theta) * cos(phi);
phihat[1] = sin(theta) * cos(phi);
phihat[2] = -sin(phi);
rhat[0] = thetahat[1] * phihat[2] - thetahat[2] * phihat[1];
rhat[1] = thetahat[2] * phihat[0] - thetahat[0] * phihat[2];
rhat[2] = thetahat[0] * phihat[1] - thetahat[1] * phihat[0];

printf("%*.*g %*.*g %*.*g\n ", DBL_DIG + 3, DBL_DIG, rhat[0], DBL_DIG +
3, DBL_DIG, rhat[1], DBL_DIG + 3, DBL_DIG, rhat[2]);
return 0;
}

standard cat took 0.000000 seconds

dcorbit@DCORBIT 64 /c/tmp
$ gcc --version
gcc.exe (GCC) 3.2 (mingw special 20020817-1)
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
dcorbit@DCORBIT 64 /c/tmp
$ gcc -W -Wall -ansi -pedantic foo.c -lm
No problem with 3.3:

% cat foo.c
#include <stdio.h>
#include <math.h>
#include <float.h>
#ifndef M_PI
#define M_PI 3.1415926535897 932384626433832 795028841971693 993751
#endif
#define deg2radian(x) ((M_PI/180) * (x))
int main(void)
{
double theta,
phi;
double thetahat[3],
phihat[3];
double r;
double rhat[3];
int converted;

oops:
printf("Enter theta, phi, r\n");
converted = scanf("%lf %lf %lf", &theta, &phi, &r);
if (converted != 3) goto oops;

theta = deg2radian(thet a);
phi = deg2radian(phi) ;
thetahat[0] = -sin(theta);
thetahat[1] = cos(theta);
thetahat[2] = 0;
phihat[0] = cos(theta) * cos(phi);
phihat[1] = sin(theta) * cos(phi);
phihat[2] = -sin(phi);
rhat[0] = thetahat[1] * phihat[2] - thetahat[2] * phihat[1];
rhat[1] = thetahat[2] * phihat[0] - thetahat[0] * phihat[2];
rhat[2] = thetahat[0] * phihat[1] - thetahat[1] * phihat[0];

printf("%*.*g %*.*g %*.*g\n ", DBL_DIG + 3, DBL_DIG, rhat[0], DBL_DIG +
3, DB

return 0;
}

% gcc -W -Wall -ansi -pedantic foo.c -lm
% gcc --version
gcc (GCC) 3.3
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
%

Unfortunately, I don't have 3.4 installed on anything right now.

I guess that if we see his code, the actual error will become obvious.

** Posted from http://www.teranews.com **
Aug 7 '08 #6
amarapreet <am**@localhost .localdomainwri tes:
hi gcc 3.4 says in a warning that %lf is not recognized as a scanf
format specifier is this right if so how to read in a double using
scanf thanks
"%lf" is the correct format specifier to read a double using scanf in
both C90 and C99.

You haven't shown us either your code or the warning. If you had
posted the exact code that you fed to the compiler (copy-and-paste a
complete program; don't try to re-type it) *and* the exact diagnostics
the compiler gave you, then we could probably tell you what the
problem is. Given the lack of information you've shared with us,
though, we can only guess.

Here's my guess. You wrote something like this:

double d;
scanf("%lf", d);

and the warning was something like this:

c.c:5: warning: format '%lf' expects type 'double *', but argument 2 has type 'double'

scanf needs the address of the object you're reading, not the value of
the object:

double d;
scanf("%lf", &d);

Don't blame me if I've guessed wrong. Show us the code and the
warning.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Aug 8 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
7987
by: Intaek LIM | last post by:
Hello. I always used cin in C++ for standard input. But, with C, I must use scanf. Integers, chars are all fine with scanf. The problem is... I cannot read floating point value like 'double' with scanf. ----------------------- double d;
4
17197
by: sushant | last post by:
hi why do we use '&' operator in scanf like scanf("%d", &x); but why not in printf() like printf("%d" , x); thnx in advance sushant
17
4817
by: Martin Jørgensen | last post by:
Hi, Since I'm a newbie I have some small but quick (probably) stupid questions also :-) This is my "get_double" function which takes a default argument also of type double. The function returns a value of type double so I can write something like value = getdouble(0.5); in my program. --------------
6
1698
by: John | last post by:
I'm new to C and I know this is probably one of those "most commonly mis-interpreted as a problem", newcomer type of question, but for this code: double x; printf("Enter number:"); scanf("%f", &x); printf("The number is %f", x);
9
2683
by: Cao Yi | last post by:
Hi, here's a fract of codes, and what's the line "scanf("%lf%*", &cvi)" doing? ============================= do { printf("\nCoefficient: "); scanf("%lf%*", &cvi); getchar(); } while (cvi <= 0.0);
26
4532
by: tesh.uk | last post by:
Hi Gurus, I have written the following code with the help of Ivor Horton's Beginning C : // Structures, Arrays of Structures. #include "stdafx.h" #include "stdio.h" #define MY_ARRAY 15
8
5135
by: pereges | last post by:
Hi, can anyone please tell me what is wrong in this program and why does it keep givng nan as the output(eg. take input as 1.2e+10) ? #include <stdio.h> #define PLANCK 6.626068e10-34 int main(void) {
22
2771
by: Bill Reid | last post by:
I just noticed that my "improved" version of sscanf() doesn't assign floating point numbers properly if the variable assigned to is declared as a "float" rather than a "double". (This never cropped up before, since I rarely use "float"s for anything, and hardly ever use the function for floating-point numbers in the first place; I just was messing around testing it for all cases and noticed a problem.) Anyway, it is declared and I...
3
2297
by: yxxxxy | last post by:
Hi, this is a part of my program code. i want to ask two questions. int time; float rate; float salary; printf("Enter # of hours worked (-1 to end):"); scanf("%d",&time);
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9325
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8244
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.