Thread: run time error

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    55

    run time error

    Code:
    /* Extract and print the second rightmost digit of the integral portion of a double */
    
    #include <stdio.h>
    
    int main (void)
    {
    /* Local Definitions */
    int digit;
    double number;
    
    /*Statements */
    printf("Enter a floating point number: ");
    scanf("%f", &number);
    
    digit=((int)number / 10) %10;
    
    printf("\nSecond rightmost digit of integral is %d\n", digit);
    
    return 0;
    
    } /*  main */
    y is the a run time error when i run it using Microsoft Visual C++?

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Code:
    double number;
    scanf("%f", &number);
    Try "%lf".
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    55
    i changed it to %lf ... it still the same ....

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    http://h18009.www1.hp.com/fortran/do...rr/rtc6xxx.htm
    C Run-Time Error R6002
    floating-point support not loaded

    The program needs the floating-point library, but the library was not linked to the program. One of the following may have occurred:
    • The program was compiled or linked with an option (such as /FPi87) that required a coprocessor, but the program was run on a machine that did not have a coprocessor installed.
    • A format string for a printf or scanf function contained a floating-point format specification, and the program did not contain any floating-point values or variables.
    • The compiler minimizes a program's size by loading floating-point support only when necessary. The compiler cannot detect floating-point format specifications in format strings, so it does not load the necessary floating-point routines.
    • Use a floating-point argument to correspond to the floating-point format specification, or perform a floating-point assignment elsewhere in the program. This causes floating-point support to be loaded.
    • In a mixed-language program, a C library was specified before a FORTRAN library when the program was linked. Relink and specify the C library last.
    Apparently, a simple fix may be to add at least one floating-point math operation to the program. Try this.
    Code:
    double number = 1.0 / 1.0;
    Last edited by Dave_Sinkula; 10-29-2003 at 09:47 AM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Oct 2003
    Posts
    55
    how come it suddenly related to string ? i didnt declare any character type variable also ....

    mind to futher the explanation ?

    i am still new to the language ...

  6. #6
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    I had that problem with a farhenheit to celsius program why do you need the .0 with a floating point number. When i didn't have it in linux it compiled but truncuated instead of giving me the floating point number

  7. #7
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    >how come it suddenly related to string ?

    I might feel that the cast from float to int should involve a floating point operation, but that might not be true.

    Assuming it is not, the program's lone floating-point involvment is in the scanf call. This information is contained in the format string and in its corresponding parameter (but no argument type checking is done on the ... for variadic functions). And a string would generally not appear to be a floating-point operation.

    From the information I found, it appears that since the no floating-point operation is performed anywhere else, the compiler assumes the floating point stuff is not needed and doesn't bring it along.

    >why do you need the .0 with a floating point number.

    To tell the compiler that you want a floating-point number.

    You might not want the compiler to see 4 / 2 and automatically start doing floating-point stuff when you intended to do integer math. Where there is ambiguity, it is up to the programmer to tell the compiler when floating-point is intended and when it is not.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  8. #8
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Originally posted by stalker
    i changed it to %lf ... it still the same ....
    Interesting. Borland 5.5.1 has no such problem.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM