當我從msys命令行運行該程序時,它會通知打開一個名爲calc.exe(程序名稱)的窗口,並顯示以下錯誤: calc.exe遇到問題並需要關閉。對此造成的不便,我們表示歉意。爲什麼我的C程序崩潰?
這裏是我的主要功能:
int main(int argc, char *argv[])
{
int num1, num2, ans;
hist_file_create();
if (argc < 2 || argc > 2)
kill("ERROR: Use: calc <operation_type>");
char operation_type = argv[2][0];
switch(operation_type)
{
// Addition
case 'a':
printf("Enter a number:\n");
scanf("%d", &num1);
printf("Enter a second number\n");
scanf("%d", &num2);
ans = num1 + num2;
printf("%d + %d = %d", num1, num2, ans);
break;
// Operation type list
case 'l':
operation_type_list();
break;
default:
kill("Invalid operation type. To see a list of recognised operation types, type l");
}
system("PAUSE");
}
我知道這是可能仍然很凌亂,但右nnow我只是想,使其工作,後來清理。 您可能需要的任何其他信息我會給。
你可以把完整的代碼,我的意思是'hist_file_create()'和'operation_type_list()'的定義? –
是的。我可以pastebin它,如果你像 – mee
@mat - ita崩潰時,我運行程序從命令行,與「calc a」或「calc l」。而不是執行這兩種情況下的代碼,它崩潰 – mee