F
Frank Chow
Please see the following code:
/* main.c */
#include <stdio.h>
int main()
{
double d;
scanf("%f", &d);
printf("%g\n", d);
}
The problem is, whatever I input to stdin (even an illegal data), the
program just print a number that seems to be a data from "raw memory",
ie uninitialized memory (for example: "5.35162e-315").
And if I replace the statement "double d" with "double d = 3.14", then
I'll always get the output "3.14" for whatever I input (even an
illegal data).
Then I may get the conclusion that the "scanf" statement never does
its job. And I have tried this under 3 compilers and none of them give
the right result.
Please give me some explanation about this.
Thanks.
/* main.c */
#include <stdio.h>
int main()
{
double d;
scanf("%f", &d);
printf("%g\n", d);
}
The problem is, whatever I input to stdin (even an illegal data), the
program just print a number that seems to be a data from "raw memory",
ie uninitialized memory (for example: "5.35162e-315").
And if I replace the statement "double d" with "double d = 3.14", then
I'll always get the output "3.14" for whatever I input (even an
illegal data).
Then I may get the conclusion that the "scanf" statement never does
its job. And I have tried this under 3 compilers and none of them give
the right result.
Please give me some explanation about this.
Thanks.