C语言中内存操作函数memcmp
2014-01-16 09:06
239 查看
六、memcmp
Memcmp会比较内存区域buf1和buf2的前count个字节.Memcmp回根据ASCLL码表顺序依次比较.当buf1<buf2时,返回<0;当buf1=buf2时,返回0;当buf1>buf2时,返回>0.
运行结果:p1<p2
名称: | memcmp |
功能: | 比较两个内存空间的字符 |
头文件: | #include <stdlib.h> |
函数原形: | int memcmp(void *buf1,void *buf2,unsigned int count); |
参数: | buf1 内存区 buf2 内存区 count 要比较的字符数 |
返回值: | 见下面 |
main() { int *p1=NULL; int *p2=NULL; int rt; p1=malloc(sizeof(int)*10); if(p1==NULL) exit(1); p2=malloc(sizeof(int)*10); if(p2==NULL) exit(1); memset(p1,'a',sizeof(int)*10); memset(p2,'b',sizeof(int)*10); rt=memcmp(p1,p2,sizeof(int)*10); if(rt>0) printf("p1>p2); if(rt<0) printf("p1<p2"); if(rt==0) printf("p1=p2"); free(p1); free(p2); } |
相关文章推荐
- C语言内存操作函数和一般字符串操作函数
- C语言中内存操作函数memset
- c语言内存操作函数汇总
- C语言中几种常见的内存操作函数(非调用)
- C语言内存(堆内存\栈内存)操作函数大全
- C语言中内存操作函数 - malloc/calloc ,free
- 内存操作函数memcpy,memccpy,memmove,memchr,memcmp,memicmp,memset
- C语言内存操作函数汇总
- c语言内存操作函数
- C语言 内存操作函数
- 自己实现内存操作函数memset(),memcmp(),memcpy(),memmove()
- C语言memcmp()函数:比较内存前n个字节
- c语言学习之基础知识点介绍(十九):内存操作函数
- C语言中内存操作函数
- 【C语言】 字符串操作函数及内存拷贝函数归总
- c语言第二周总结-程序存储区划分/动态申请内存/内存操作函数
- 《IOS_C语言》程序存储区划分、动态申请内存、内存操作函数
- c语言内存操作函数汇总
- 【总结】C语言中常见的内存操作函数汇总
- 内存操作函数memcpy,memccpy,memmove,memchr,memcmp,memicmp,memset