基本介紹
- 中文名:strncmpi
- 函式名:: strnicmp
- 用 法:: int strnicmp
- 功 能:: 將一個字元串中的一部分
簡介,說明,函式代碼,例一,例二,
簡介
, 大小寫不敏感
(char *str1, char *str2, unsigned maxlen);
說明
strncmpi是到strnicmp的宏定義
當s1<s2時,返回值<0
當s1=s2時,返回值=0
當s1>s2時,返回值>0
函式代碼
例一
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "BBB", *buf2 = "bbb";
int ptr;
ptr = strnicmp(buf2, buf1);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n");
else if (ptr < 0)
printf("buffer 2 is less than buffer 1\n");
else
printf("buffer 2 equals buffer 1\n");
return 0;
}
運行結果:buffer 2 equals buffer 1
標題錯了,應該是strnicmp (strncmpi編譯出錯,貌似沒有這個函式。)
例二
// strnicmp.c
#include <syslib.h>
#include <string.h>
main()
{
char *s1="Hello, Programmers!";
char *s2="Hello, programmers!";
int r;
clrscr();
r=strnicmp(s1,s2,strlen(s1));
if(!r)
printf("s1 and s2 are identical");
else
if(r<0)
printf("s1 less than s2");
else
printf("s1 greater than s2");
getchar();
return 0;
}