VS2005中没有strcasecmp和strncasecmp函数,需要自己添加。
在.h文文件中添加如下声明:
#ifdef _MSC_VER
int strcasecmp(char *s1, char *s2);
int strncasecmp(char *s1, char *s2, register int n);
#endif
在.c文件中添加如下实现
#ifdef _MSC_VER int strcasecmp(char *s1, char *s2) { while (toupper((unsigned char)*s1) == toupper((unsigned char)*s2++)) if (*s1++ == '') return 0; return(toupper((unsigned char)*s1) - toupper((unsigned char)*--s2)); } int strncasecmp(char *s1, char *s2, register int n) { while (--n >= 0 && toupper((unsigned char)*s1) == toupper((unsigned char)*s2++)) if (*s1++ == '') return 0; return(n < 0 ? 0 : toupper((unsigned char)*s1) - toupper((unsigned char)*--s2)); } #endif
另外一个比较简单的办法是用VC SDK中的函数来代替如下:
#ifdef _MSC_VER
#define strcasecmp stricmp
#define strncasecmp strnicmp
#endif