我有以下代码,它应该获取用户输入的命令,然后检查命令是否预定义。但是,无论输入什么命令,输出都是“You asked for help”。
我想问题可能与我比较用户输入字符串和设置字符串的方式有关,但我仍然需要帮助解决问题。
char command[10];
char set[10];
char set1[10];
strcpy(set, "help");
strcpy(set1, "thanks");
int a = 0;
while (a != 1)//the program should not terminate.
{
printf("Type command: ")
scanf("%s", command);
if (strcmp(set, command))
{
printf("You asked for help");
}
else if (strcmp(set1, command))
{
printf("You said thanks!");
}
else
{
printf("use either help or thanks command");
}
}