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. Advertisements

  2. daniel

    Tom St Denis Guest

    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. Advertisements

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 (here). After that, you can post your question and our members will help you out.