Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > scanf bug when retrieving a float value from a pointer to a float, in a structure

Reply
Thread Tools

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

 
 
daniel
Guest
Posts: n/a
 
      06-24-2003
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);
}




 
Reply With Quote
 
 
 
 
Tom St Denis
Guest
Posts: n/a
 
      06-24-2003
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple structure and copying data to pointer of the same structure A C++ 27 04-16-2011 11:07 PM
float to string to float, with first float == second float Carsten Fuchs C++ 45 10-08-2009 09:47 AM
difference between scanf("%i") and scanf("%d") ??? perhaps bug inVS2005? =?ISO-8859-1?Q?Martin_J=F8rgensen?= C Programming 18 05-02-2006 10:53 AM
scanf (yes/no) - doesn't work + deprecation errors scanf, fopen etc. =?ISO-8859-1?Q?Martin_J=F8rgensen?= C Programming 185 04-03-2006 02:49 PM
Re: float->byte->float is same with original float image. why float->ubyte->float is different??? bd C Programming 0 07-07-2003 12:09 AM



Advertisments