我试图让一个程序让用户输入一个单词或字符,存储它,然后打印它,直到用户再次键入它,退出程序.我的代码看起来像这样:
#include <stdio.h>
int main()
{
char input[40];
char check[40];
int i=0;
printf("Hello!\nPlease enter a word or character:\n");
gets(input);
printf("I will now repeat this until you type it back to me.\n");
while (check != input)
{
printf("%s\n", input);
gets(check);
}
printf("Good bye!");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
问题是我不断打印输入字符串,即使用户输入(检查)与原始(输入)匹配.我比较错误吗?
我在这里有一个结构,例如:
char *sname;
........
players[i].sname
Run Code Online (Sandbox Code Playgroud)
等于"詹姆斯".
我需要检查值之间的相等性,如下所示:
if (players[i].sname == 'Lee')
Run Code Online (Sandbox Code Playgroud)
但我没有太多运气.是否有一个str*我应该使用的功能,或者无论如何都要修复我的if陈述?