在网上看到一个关于strcasecmp的一个例子程序,如下:
#include<stdio.h>
#include<string.h>
int main()
{
char *a="abcdef";
char *b="AbCdEf";
if(!strcasecmp(a,b))
printf("%s=%s\n",a,b);
return 0;
}
可是在编译之后出现错误提示:error C2065: 'strcasecmp' : undeclared identifier。
在网上查了一下,要加上如下代码,才可以:
#if defined(_MSC_VER)
#define strcasecmp _stricmp
#endif
不过,我没明白为什么是可以的。后来查了查,原来,MS使用stricmp和strcasecmp的功能是一样的。
若:
#include<stdio.h>
#include<string.h>
int main()
{
char *a="abcdef";
char *b="AbCdEf";
if(!stricmp(a,b))
printf("%s=%s\n",a,b);
return 0;
}
则是可以的。strcasecmp是BSD的标准。