<分区>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
const int SIZE = 100;
char input[SIZE];
while(1)
{
fgets (input, SIZE - 2, stdin); // input
printf("%d", strcmp(input, "exit")); //returining 10 instead of 0
if(strcmp(input, "exit") == 0)
{
printf("SHELL Terminated\n");
exit(0);
}
return 0;
}
我遇到了一个问题。如果我在 input
变量中输入 exit,函数 strcmp()
返回 10
,但它应该返回 0
并退出程序,因为 exit 等于 exit。但事实并非如此。
我找不到问题。