c - _stricmp 未按预期进行比较
问题描述
我写了这个简单的脚本,它让我发疯了。我不明白为什么我做的比较总是不一样。
这是我的代码:
int main()
{
char test[]="boy";
char test2[20];
fgets(test2, 20, stdin);
if (_stricmp(test2, test) == 0)
{
printf("the same");
}
else
{
printf("Not");
}
}
如果我插入“男孩”这个词,我仍然会弄错。
问题是什么?
解决方案
所以看起来我们应该添加一个新行,然后效果很好
char test[]="boy\n"
;
推荐阅读
- vba - 根据打开的工作簿设置工作簿
- git - 从提交历史记录中删除大于 100MB 的文件 - 迁移到 Github 失败
- flutter - 如何保存一个字符串的每个键/数据,该字符串具有多个共享优先级的键/数据?
- javascript - Visual Studio 代码“Cick-Through / Go-To”不适用于 jsconfig.json(和 Next.js)中的路径别名
- javascript - 如何将类名作为参数传递并调用 GWT jsni 中的常用静态方法?
- python - 如何使用 Python 测试 timescaledb 数据库
- wordpress - php更新后Wordpress ajax 500错误
- kubernetes - 仅使用 REST API 访问 kubernetes 集群详细信息,例如命名空间及其 pod 和 pod 映像
- azure - 如果数据保留期超过 90 天,Azure Insights 的费用是多少?
- bash - 为什么我可以跳过命令行参数的空白(例如,脚本 -ARGNAMEargvalue)?