Implementation of "C language" memcmp function

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.