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

  • Follow


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;
};

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);
}




0
Reply bignat (1) 6/24/2003 2:09:11 PM

daniel wrote:

>> #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

0
Reply tomstdenis3 (162) 6/24/2003 2:33:33 PM


1 Replies
63 Views

(page loaded in 0.074 seconds)

Similiar Articles:




7/17/2012 5:43:20 PM


Reply: