【问题标题】:Native' has exited with code 3 (0x3)Native' 已退出,代码为 3 (0x3)
【发布时间】:2013-10-09 10:05:37
【问题描述】:

我在调试这段代码时遇到以下问题:

// 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;
}

产生这个错误:

'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).

谁能说出我的问题出在哪里?

我使用 MS VS 2010 Prof IDE。

【问题讨论】:

  • 您有什么理由使用 C 风格的字符串和 C 风格的函数,例如 fopen
  • 什么是system("exit")
  • 是的,它是一个开着 ca 2000 的舞会,关闭其他 E/A 突击队,如果可能的话,我不想改变它们。系统(“退出”);来自好的旧 DOS 它很容易关闭程序
  • 它没有,您必须使用 exit() 代替。退出代码倾向于匹配异常退出时的操作系统错误代码,3 =“找不到路径”。很多巧合。

标签: c++ visual-c++ runtime-error visual-studio-debugging


【解决方案1】:
do {
    scanf("%s", eingabe);
} while ( getchar() != '\n');

逐字读取文件不是一个幸运的选择。您可以这样做(C 风格的方法):

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

或使用std::strings 和流代替(C++):

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

虽然我认为在这种情况下您只想读取带有文件名的 1 行:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-10
    • 2018-07-25
    • 1970-01-01
    • 2012-07-20
    相关资源
    最近更新 更多