java memcmp_memcmp,memicmp函数

函数原型:extern int memcmp(void *str1, void *str2, unsigned int n)

参数说明:str1和str2为指定作比较的字符串,比较两个字符串的前n个字节。

所在库名:#include

函数功能:比较字符串str1和str2在内存区域中的的前n个字节是否相同。

返回说明:当str1str12时,返回值>0。

其它说明:暂时无。

实例:

6896a36156cf7e8005f74c9be54ad118.gif

#include

<

string

.h

>

6896a36156cf7e8005f74c9be54ad118.gif#include

<

stdio.h

>

6896a36156cf7e8005f74c9be54ad118.gif

6896a36156cf7e8005f74c9be54ad118.gif

int

main()

180e03127793efd57566a2f54560407c.gif

{

f99dbbdf22ffb8659f8ab4d5beb1cb9b.gifchar*str1="I'm sky2098,welcome to my website!";

f99dbbdf22ffb8659f8ab4d5beb1cb9b.gifchar*str2="I'm sky2098,please do not call me sky2098!";

f99dbbdf22ffb8659f8ab4d5beb1cb9b.gifintinttemp;

f99dbbdf22ffb8659f8ab4d5beb1cb9b.gif    inttemp=memcmp(str1,str2,strlen("I'm sky2098,"));//比较str1和str2在内存区中前strlen("I'm sky2098,")个字节是否相等f99dbbdf22ffb8659f8ab4d5beb1cb9b.gifif(inttemp==0)

981bf484a2b559088436e156da1c4fe6.gif{

f99dbbdf22ffb8659f8ab4d5beb1cb9b.gif      printf("str1 and str2 has n bytes which are the same as each other!/n");

aa57e4afa8d3e136cb00b34400d84a0e.gif   }f99dbbdf22ffb8659f8ab4d5beb1cb9b.gifreturn0;

db483cb91b7ced033b1b5cf3b1bcb286.gif}

在VC++ 6.0  编译运行:

60c16dff051753254a2098371b150df7.png

尤其注意了,memcmp函数实现的是字节的比较,而不是字符的比较。

函数原型:extern int memicmp(void *str1, void *str2, unsigned int count)

参数说明:str1和str2为指定作比较的字符串,比较两个字符串的前count个字节,不区分大小写。

所在库名:#include

函数功能:比较字符串str1和str2在内存区域中的的前count个字节是否相同。

返回说明:当str1str12时,返回值>0。

其它说明:暂时无。

实例:

6896a36156cf7e8005f74c9be54ad118.gif

#include

<

string

.h

>

6896a36156cf7e8005f74c9be54ad118.gif#include

<

stdio.h

>

6896a36156cf7e8005f74c9be54ad118.gif

6896a36156cf7e8005f74c9be54ad118.gif

int

main()

180e03127793efd57566a2f54560407c.gif

{

f99dbbdf22ffb8659f8ab4d5beb1cb9b.gifchar*str1="I'm sky2098,welcome to my website!";  //两个字符串含义相同,但是大小写不同

f99dbbdf22ffb8659f8ab4d5beb1cb9b.gifchar*str2="I'm SKY2098,WELCOME TO MY website!";

f99dbbdf22ffb8659f8ab4d5beb1cb9b.gifintinttemp;

f99dbbdf22ffb8659f8ab4d5beb1cb9b.gif    inttemp=memicmp(str1,str2,strlen("I'm sky2098,welcome to my website!"));//比较str1和str2在内存区中前strlen("I'm sky2098,welcome to my website!")个字节是否相等f99dbbdf22ffb8659f8ab4d5beb1cb9b.gifif(inttemp==0)

981bf484a2b559088436e156da1c4fe6.gif{

f99dbbdf22ffb8659f8ab4d5beb1cb9b.gif      printf("str1 and str2 has n bytes which are the same as each other!");

aa57e4afa8d3e136cb00b34400d84a0e.gif   }f99dbbdf22ffb8659f8ab4d5beb1cb9b.gifreturn0;

db483cb91b7ced033b1b5cf3b1bcb286.gif}

在VC++ 6.0  编译运行:

4cbf45c106a991dfe4d601538f7f0b15.png

memicmp函数在比较的时候是不区分字母大小写的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值