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

Discussion in 'C Programming' started by daniel, Jun 24, 2003.

  1. daniel

    daniel Guest

    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);
    }
    daniel, Jun 24, 2003
    #1
    1. Advertising

  2. daniel

    Tom St Denis Guest

    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
    Tom St Denis, Jun 24, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bd
    Replies:
    0
    Views:
    624
  2. =?ISO-8859-1?Q?Martin_J=F8rgensen?=

    scanf (yes/no) - doesn't work + deprecation errors scanf, fopen etc.

    =?ISO-8859-1?Q?Martin_J=F8rgensen?=, Feb 16, 2006, in forum: C Programming
    Replies:
    185
    Views:
    3,390
    those who know me have no need of my name
    Apr 3, 2006
  3. =?ISO-8859-1?Q?Martin_J=F8rgensen?=

    difference between scanf("%i") and scanf("%d") ??? perhaps bug inVS2005?

    =?ISO-8859-1?Q?Martin_J=F8rgensen?=, Apr 26, 2006, in forum: C Programming
    Replies:
    18
    Views:
    674
    Richard Bos
    May 2, 2006
  4. Carsten Fuchs
    Replies:
    45
    Views:
    1,540
    James Kanze
    Oct 8, 2009
  5. A
    Replies:
    27
    Views:
    1,596
    Jorgen Grahn
    Apr 17, 2011
Loading...

Share This Page