相关疑难解决方法(0)

如何正确比较字符串?

我试图让一个程序让用户输入一个单词或字符,存储它,然后打印它,直到用户再次键入它,退出程序.我的代码看起来像这样:

#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)

问题是我不断打印输入字符串,即使用户输入(检查)与原始(输入)匹配.我比较错误吗?

c string strcmp

168
推荐指数
6
解决办法
41万
查看次数

标签 统计

c ×1

strcmp ×1

string ×1