Search code examples
c++visual-c++runtime-errorvisual-studio-debugging

Native' has exited with code 3 (0x3)


I have the following problem when I debug this code:

// Croppen.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include "stdlib.h" 

int i,j,c;
char hex[] = {"header.hex"},
     ziel[] = {"ergebniss.bmp"},
     eingabe[100];
FILE *f,*h;

int _tmain(int argc, _TCHAR* argv[])
{
    {//eingabe des Orginalen Bildnamens
        printf("Bitte geben sie den Bild namen ein. Maxiaml 20 Zeichen, mit '.bmp'\n");

        do { scanf("%s", eingabe); } while ( getchar() != '\n' );

        if ((f = fopen(eingabe,"rb")) == NULL)
        {
            printf("Fehler beim Öffnen von %s\n",eingabe);
            system("exit");
        }
    }

    {//header einlesen
        h = fopen(hex,"wb");
        for (i = 0; i < 52; i++) { putc(getc(f),h); }
    }

    return 0;
}

Produces this error:

'Croppen.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Symbols loaded (source information stripped).
The program '[2884] Croppen.exe: Native' has exited with code 3 (0x3).

Can any one say where my problem is?

I use the MS VS 2010 Prof IDE.


Solution

  • do {
        scanf("%s", eingabe);
    } while ( getchar() != '\n');
    

    isn't a lucky choice for reading from file word by word. You could either do (C-style approach):

    while (scanf("%s", eingabe) == 1) {
        ...
    }
    

    or use std::strings and streams instead (C++):

    std::string word;
    while (std::cin >> word) {
        ...
    }
    

    although I think you just want to read 1 line with a filename in this case:

    std::string filename;
    if (std::getline(std::cin, filename)) {
        ...
    }