The realization of the strcmp of the C language of the evil complement

Source: Internet
Author: User
Tags strcmp

strcmp () function description

The corresponding characters in the two strings are compared in the order of the ASCII table, and 0 is returned, and the subtraction is returned by different values.

set these two strings to STR1,STR2,

if STR1==STR2, returns 0;

if STR1>STR2, a positive number is returned;

if STR1<STR2, a negative number is returned.


Note: Different compilers have different rules for return values


int strcmp (char* str1, char* str2) {

while (*str1 && *str2 && *str1==*str2) {

++STR1;

++STR2;

}

return *STR1-*STR2;

}


The realization of the strcmp of the C language of the evil complement

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.