memcmp is a comparisonMemorythe first count bytes of the zone Buf1 and Buf2. Thefunctionis bybytescompared to the. header File#include <string.h>int memcmp (const void *BUF1, const void *BUF2, unsigned int count);compares the memory area BUF1 and the first count bytes of buf2. header File#include <string.h> or #include<memory.h>return valuewhen Buf1<buf2, the return value <0when Buf1=buf2, the return value =0when Buf1>buf2, the return value >0So the function is implemented as:
<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== '} ') return 0;str1++;str2++;}} if (*STR1>*STR2) return 1;if (*STR1<*STR2) return-1;} int main () {char *p= "ADCC"; char *q= "BAC";p rintf ("%d\n", my_memcmp (p,q,1)); return 0;} </span>
Operation Result:
Implementation of "C language" memcmp function