scanf bug when retrieving a float value from a pointer to a float, in a structure 
Author Message
 scanf bug when retrieving a float value from a pointer to a float, in a structure

Hi!

Anyone may help, please?!..

The C/C++ compiler from Visual Studio 6.0 gives
me a very strange error: "floating point not loaded"
when i try to retrieve a float with scanf, in a pointer
to a float in a structure..

If I retrieve it first in a buffer (float, of course) there are
no more errors. I mean, any subsequent calls to other
'wrong' style float input, works after this kind of trick.

On some computers it works well, on other it throws
that error message.

Someone told me there is a compiler option that should
fix this. Anybody knows how to fix that?

=======
Details:
The problems occurs in this kind of situation:

#include <stdio.h>

struct person {
 char name[20];
 float salary;

Quote:
};

void main() {
 struct person p[2];

 printf(" Give me the salary: ");
 scanf("%f", &p[0].salary);

 printf(" the salary is: %.2f \n\n", p[0].salary);

Quote:
}



Sat, 10 Dec 2005 22:09:11 GMT  
 scanf bug when retrieving a float value from a pointer to a float, in a structure

Quote:

>> #include <stdio.h>

> struct person {
>  char name[20];
>  float salary;
> };

> void main() {
>  struct person p[2];

>  printf(" Give me the salary: ");
>  scanf("%f", &p[0].salary);

>  printf(" the salary is: %.2f \n\n", p[0].salary);
> }

This worked for me in MSVC 6.00 [SP5] even when I entered non-floating
point values such as "a" and "tom".

Compiled with no optimizations and /Ox, I've tried the various cpu
models [default blended, /G3].  Sorry to say I cannot reproduce the bug.

Tom



Sat, 10 Dec 2005 22:33:33 GMT  
 scanf bug when retrieving a float value from a pointer to a float, in a structure

Quote:
>Anyone may help, please?!..

Yup, the FAQ.

Dan
--
Dan Pop
DESY Zeuthen, RZ group



Sun, 11 Dec 2005 00:46:58 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. float != float and floats as return types

2. Floats as boolean values; generic function pointers

3. Why Wont This Compile Right--Pointer to Pointer to Pointer to Float

4. how to retrieve the value obtained by scanf

5. scanf : floating point format not linked

6. scanf problem with float

7. Help with scanf and double float input

8. Error !!! scanf : floating point formats not linked

9. using scanf to gather an int and float??

10. scanf floating number problem

11. Floating point numbers -- scanf

12. scanf() and float problems in Turbo C 2.0

 

 
Powered by phpBB® Forum Software