我有一个简单的程序,但我遗漏了一些东西,因为当它比较输入的字符串时,它总是不等于 0。
我的代码:
#include <stdio.h>
#include <string.h>
int main()
{
int loop = 1;
char response[9];
char *Response;
printf("Enter a string: ");
while(loop = 1)
{
scanf("%s", &response);
Response = response;
if(strcmp(Response,"Random") != 0 || strcmp(Response,"Database") != 0 || strcmp (Response,"Both") != 0)
printf("\n\"%s\" is an invalid entry. Valid responses are: \"Random\", \"Database\", or \"Both\": ", Response);
else
break;
}
printf("\nYour string is: %s\n", Response);
return 0;
}
当我输入“Random”、“Database”或“Both”时,它仍然认为该字符串无效。请帮忙。谢谢!