Â¥Ö÷
×êʯ»áÔ±
×¢²á£º2017-12-20
µÇ¼£º2019-12-30
|
memcmpÊDZȽÏÄÚ´æÇøÓòbuf1ºÍbuf2µÄÇ°count¸ö×Ö½Ú¡£¸Ãº¯ÊýÊÇ°´×ֽڱȽϵġ£
Í·Îļþ #include <string.h>
int memcmp(const void *buf1, const void *buf2, unsigned int count); ±È½ÏÄÚ´æÇøÓòbuf1ºÍbuf2µÄÇ°count¸ö×Ö½Ú¡£
Í·Îļþ #include <string.h>»ò#include<memory.h>
·µ»ØÖµ µ±buf1<buf2ʱ£¬·µ»ØÖµ<0 µ±buf1=buf2ʱ£¬·µ»ØÖµ=0 µ±buf1>buf2ʱ£¬·µ»ØÖµ>0
ËùÒԸú¯ÊýµÄ¹¦ÄÜʵÏÖΪ£º [html] view plain copy
<span style="font-size:18px;">#include<stdio.h> #include<assert.h> int my_memcmp(char *str1,char *str2,int len) { assert(str1); assert(str2); while(len--) { while(*str1==*str2) { if(*str1=='\0') return 0; str1++; str2++; } } if(*str1>*str2) return 1; if(*str1<*str2) return -1; } int main() { char *p="adcc"; char *q="bac"; printf("%d\n",my_memcmp(p,q,1)); return 0; }</span>
ÔËÐнá¹ûÈçͼËùʾ£º
|
- ÔÞ(0)
-
Â¥Ö÷ 2018-01-18 10:00:59
|