"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 **