Fehler bei scanf() in Visual c++

Hallo Leute,

einfaches Programm:

#include 

int main(void)
{
 double a;
 scanf("%lf", &a);
}

ergibt in Visual C++ immer einen Fehler nach Eingabe einer Zahl:

Microsoft Visual C++ Debug Library
Programm: (programmname)
runtime error

Der Code sollte korrekt sein und funktioniert mit dem Freeware-Compiler von Bloodshed Software auch einwandfrei.

Weiß jemand warum der MS-Compiler das nicht mag? Mit scanf bei int gibts die Probleme übrigens nicht.

Gruß
Marian

Hi Marian,

es tritt der Runtime error R6002 auf. Die MSDN schreibt dazu folgendes:

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:

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

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

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

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

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

Dabei löst 3) + 4) wohl hier das Problem. Ändere den Code einfach zu:

#include 

int main(void)
{ 
 double a = 0.0;

 scanf("%lf", &a);

 return 0;
}

Die Zuweisung eines Wertes auf die Variable ‚a‘ veranlasst den Linker den floating-point support zu laden. Nettes Problem…

Gruss Rolf

Hallo Rolf,

es tritt der Runtime error R6002 auf.

wo hast Du denn die Fehlernummer sehen können?

Dein Lösungsvorschlag funktioniert jedenfalls. Da hat wohl der Compiler einfach die Bibliothek wegoptimiert :smile:

Gruß
Marian

Hallo Marian,

wo hast Du denn die Fehlernummer sehen können?

In der Release-exe wurde der Fehler auf die Konsole augegeben.

Gruss Rolf