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