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

D

daniel

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

Tom St Denis

daniel said:
#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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top