为了澄清目的,我需要程序打印输入a和b的数字,而不是实际的字母a和b.
好的,这是每个yall建议的修订程序:
int main (int argc, char *argv[]) { int a; /*first number input*/ int b; /*second number input*/ a = atoi(argv[1]); /*assign to a*/ b = atoi(argv[2]); /*assign to b*/ if (a < b) printf("%s\n", a < b); /* a is less than b*/ else { printf("%s\n", a >= b); /* a is greater than or equal to b*/ } if (a == b) printf("%s\n", a == b); /* a is equal to b*/ else { printf("%s\n", a != b); /* a is not equal to b*/ } return 0; } /* end function main*/
大声笑,现在当我运行程序时,我被告知
8 [main] a 2336 _cygtls::handle_exceptions: Error while dumping state Segmentation fault
这是什么意思?(如果你现在还没有注意到我对这个东西很无望lol).
您要求printf()
打印布尔表达式的值(对于true和false,它们总是分解为1或0).
您可能希望您的代码看起来更像:
if (a < b) printf("%s\n", "a < b"); /* a is less than b*/ else { printf("%s\n", "a >= b"); /* a is greater than or equal to b*/ }
将结果显示为字符串.
这一行:
if (a = b)
不应该
if (a == b)
同样在这里:
printf("%d\n", a = b); /* a is equal to b*/
应该
printf("%d\n", a == b); /* a is equal to b*/