0
當我調用這個函數時,它總是返回false並停止程序。但我不知道爲什麼。C - 我的功能回火
// checks to see if the second argument is a positive interger,
// and that there is only one arg
if (ArgCheck (argc, shift) == false)
{
printf("You may only input one non-negative argument.\n");
return 1;
}
else
return true;
功能ArgCheck
是:
int ArgCheck (int a, int b)
{
if (a > 2)
{
return false;
}
else if (b < 0)
{
return false;
}
else
return 0;
}
即使當我在適當的參數在命令行中輸入,它仍然返回false。我知道它是一個noob問題,但我很感激幫助。
謝謝。
um,'0 == false'。 C是嚴格打字的。 – Dave
你的一個函數返回'true'和'1',另一個'false'和'0' - 請堅持在相同的函數中返回相同的類型(例如,在同一個函數中只返回'true'或'false' ,不要在那裏混合'0'和'1',反之亦然)。另外,不是'true' ='1'和'false' ='0'(通常?),所以你的函數在所有情況下都會返回相同的結果? – Dukeling
你在C中有''true''和''false''嗎? – gongzhitaao