Function name : strnicmp
Header file : <string.h>
Function prototype : int strnicmp(const char *str1,const char *str2,unsigned n);
Function : Compare two strings of specified length, but not case sensitive
Parameters : str1 and str2 are the strings to be compared.
unsigned n is the number of strings to be compared
Return value : str1 > str2 returns a value greater than 0;
str1==str2 returns a value equal to 0;
str1 < str2 returns a value less than 0;
Note : This function returns not a fixed value such as 1 or -1, but a value greater than or less than 0
Program example : Compare the size of the first n characters of string str1 and str2
#include<stdio.h>#include<string.h>intmain(void){char*str1=www.dotcpp.com;char*str2=WWW.DOTCPP.COM;intp=strnicmp(str2,str1,3) ;if(p>0){printf(str2isgreaterthanstr1n);}elseif(p<0){printf(str2islessthanstr1n);}else{printf(str2isequalsstr1n);}return0;}
Running results:
str2isequalsstr1