Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   scanf bug when retrieving a float value from a pointer to a float, in a structure (http://www.velocityreviews.com/forums/t313771-scanf-bug-when-retrieving-a-float-value-from-a-pointer-to-a-float-in-a-structure.html)

daniel 06-24-2003 02:09 PM

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

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





Tom St Denis 06-24-2003 02:33 PM

Re: scanf bug when retrieving a float value from a pointer to a float,in a structure
 
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



All times are GMT. The time now is 06:39 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.