strcmp和stricmp、strcmpi三者之间的区别(C++)
原文:http://www.cnblogs.com/tankeee/p/3957629.html
#include <string.h>
#include <stdio.h>
原型:extern int strcmp(const void *s1, const void *s2);
用法:#include <string.h>
功能:比較字符串s1和s2是否相同,區(qū)分大小寫(xiě)。
說(shuō)明:如果s1=s2則返回零,否則返回非零值。
原型:extern int stricmp(char *s1,char * s2);
用法:#include <string.h>
功能:比較字符串s1和s2,但不區(qū)分字母的大小寫(xiě)。
說(shuō)明:strcmpi是到stricmp的宏定義,實(shí)際未提供此函數(shù)。
當(dāng)s1<s2時(shí),返回值<0
當(dāng)s1=s2時(shí),返回值=0
當(dāng)s1>s2時(shí),返回值>0
//舉例:
void main()
{
char *str1="I am OldWolf";
char *str2="I am Oldwolf";
int cmp;
printf("原字符串分別為:n%sn%snn",str1,str2);
cmp=strcmp(str1,str2);
if (cmp!=0)
printf("strcmp比較字符串不相同!n");
else
printf("strcmp比較字符串相同!n");
cmp=stricmp(str1,str2);
if (cmp!=0)
printf("stricmp比較字符串不相同!n");
else
printf("stricmp比較字符串相同!n");
cmp=strcmpi(str1,str2);
if (cmp!=0)
printf("strcmpi比較字符串不相同!n");
else
printf("strcmpi比較字符串相同!n");
}
總結(jié)
以上是生活随笔為你收集整理的strcmp和stricmp、strcmpi三者之间的区别(C++)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 长街蛏子节在什么地方
- 下一篇: 2022中秋节有哪些看好又实用的中秋礼品