不区分大小写的串比较, 在实战中的应用还是很广泛的, 有时候可以增强程序的容错性, 下面我们来分别看看Windows下的stricmp和Linux下的strcasecmp
Windows下的stricmp:
#include <stdio.h>
#include <string.h>
int main()
{
if(0 == stricmp("abc", "ABc"))
{
printf("yes1\n"); // yes
}
if(0 == stricmp("ABCx", "ABC"))
{
printf("yes2\n"); // 不执行
}
return 0;
} Linux下的strcasecmp:
#include <stdio.h>
#include <string.h>
int main()
{
if(0 == strcasecmp("abc", "ABc"))
{
printf("yes1\n"); // yes
}
if(0 == strcasecmp("ABCx", "ABC"))
{
printf("yes2\n"); // 不执行
}
return 0;
}哈哈, 我突然发现, 自己很喜欢linux下的程序了。

本文介绍了在Windows和Linux环境下如何使用stricmp和strcasecmp函数进行不区分大小写的字符串比较,并通过示例代码展示了它们的基本用法。
3649

被折叠的 条评论
为什么被折叠?



