關於strcasecmp的一個小程序

     在網上看到一個關於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的標準。

發佈了28 篇原創文章 · 獲贊 2 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章