2013-10-09 22 views
0

,我有以下问题,当我调试代码:原住民”已退出,代码为3段(0x3)

// 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。

+0

你有什么理由为什么你使用C风格的字符串和C风格的函数,如'fopen'? – LihO

+0

什么是'system(“exit”)'? –

+0

是的,它是一个ca 2000打开的promam,关闭其他E/A突击队队员,我不想在可能的情况下更改它们。系统( “退出”);来了vome好老DOS它很容易关闭程序 –

回答

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

对于逐字读取文件不是一个幸运的选择。你既可以做(C-式的方法):

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

或使用std::string S和,而不是流(C++):虽然我觉得你只是想读1线与文件名

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

这种情况下:

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