首页 > 解决方案 > _stricmp 未按预期进行比较

问题描述

我写了这个简单的脚本,它让我发疯了。我不明白为什么我做的比较总是不一样。

这是我的代码:

int main()
{
        char test[]="boy";
        char test2[20];

        fgets(test2, 20, stdin);

        if (_stricmp(test2, test) == 0)
        {
            printf("the same");
        }
        else
        {
            printf("Not");
        }
    }

如果我插入“男孩”这个词,我仍然会弄错。

问题是什么?

标签: cstringfgets

解决方案


所以看起来我们应该添加一个新行,然后效果很好

char test[]="boy\n";


推荐阅读