複製鏈接
請複製以下鏈接發送給好友

strnicmp

鎖定
函數名: strnicmp
功 能: 比較字符串str1和str2的前n個字符串字典序的大小,但是不區分字母大小寫。
返回值: 當str1str2時,返回值是1。
比較是這樣進行的,先比較兩個字符串的第1個字符字典序的大小,如果能比較出大小,則馬上返回了,如果不能區別大小,開始比較第2個,如果這時第1個字符串已經到盡頭了,第2個字符串還有字符,這時算第2個字符串大。
中文名
比較字符串str1和str2的前n個字符串字典序的大小
外文名
strnicmp
性    質
函數名
領    域
程序設計

目錄

strnicmp例題1

char *str1="B";
char *str2="abcD";
int n=4;
strnicmp(char *str1, char *str2, 4);
在我的機器上比較出的結果是str1>str2
char *str1="ABCD";
char *str2="abcD";
int n=4;
strnicmp(char *str1, char *str2, 4);
結果一樣大。
char *str1="abc";
char *str2="abcD";
int n=5;
strnicmp(char *str1, char *str2, 5);
結果是str2大。
可以把上述數據,填到下面程序中一試便知道。
用 法: int strnicmp(char *str1, char *str2, unsigned maxlen);

strnicmp例題2

#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "BBBccc", *buf2 = "bbbccc";
int nResult;
nResult = strnicmp(buf2, buf1, 3);
if (nResult > 0)
printf("buffer 2 is greater than buffer 1\n");
if (nResult < 0)
printf("buffer 2 is less than buffer 1\n");
if (nResult == 0)
printf("buffer 2 equals buffer 1\n");
return 0;
}
//---------------------------------
還有兩種情況: (n1 = 3 或 n2= 2時)
char *str1="aBc";
char *str2="abcD";
strnicmp(char *str1, char *str2, 3);
strnicmp(char *str1, char *str2, 2);
兩種情況的結果是否應該等於 0 呢?