调试此代码时有以下问题:
// 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 2010 IDE教授。
发布于 2013-10-09 10:10:29
do {
scanf("%s", eingabe);
} while ( getchar() != '\n');逐字阅读不是一个幸运的选择。您可以这样做(C风格的方法):
while (scanf("%s", eingabe) == 1) {
...
}或者使用std::strings和streams代替(C++):
std::string word;
while (std::cin >> word) {
...
}尽管在本例中,我认为您只想阅读带有文件名的1行:
std::string filename;
if (std::getline(std::cin, filename)) {
...
}https://stackoverflow.com/questions/19268947
复制相似问题