Strcmp () [C language library function source code]

Source: Internet
Author: User

[C language library function source code]

[This program is compiled in Dev C ++ 4.9.9.2]

/*

Strcmp compares two strings and returns an integer

To indicate whether the first is less than the second,

The two are equal, or whether the first is greater than the second.

Comparison is done byte by byte on an unsigned basis,

Which is to say that null (0) is less than any other character (1-255 ).

String comparison function, which compares the source and DEST strings. If the source string is greater than the target string, 1 is returned;

If the source string is equal to the target string, 0 is returned. -1 is returned when the source string is smaller than the target string;

*/

Int my_strcmp (const char * Source, const char * DEST)

{

Int ret = 0;

While (! (Ret = * (unsigned char *) Source-* (unsigned char *) DEST) & * DEST)

Source ++, DEST ++;

If (Ret <0)

Ret =-1;

Else if (Ret> 0)

Ret = 1;

Return (RET );

}

Void print (char * str1, char * str2, int T)

{

If (t = 0)

Printf ("/n % s equal % s/n", str1, str2 );

Else if (t = 1)

Printf ("/n % s upper than % s/n", str1, str2 );

Else if (t =-1)

Printf ("/n % s lower than % s/n", str1, str2 );

}

Int main ()

{

Char * str1 = "ammana ";

Char * str2 = "Babi ";

 

Print (str1, str2, my_strcmp (str1, str2 ));

Print (str2, str1, my_strcmp (str2, str1 ));

Print (str2, str2, my_strcmp (str2, str2 ));

System ("pause ");

Return 0;

}

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.