2013-10-09 21 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)) { 
    ... 
}