C Language Implementation strcmp

Source: Internet
Author: User
Tags strcmp

Note Convert to unsigned char:

Strcmp.h

1 #ifndef Strcmp_h2 #defineStrcmp_h3 4 /***************************************************5 function: Compare strings S1 and S2. 6 general form: strcmp (S1,S2)7 return Value:8 when S1<s2, the return value <09 when S1=s2, the return value =0Ten when S1>s2, the return value >0 One ****************************************************/ A  - intCAT_STRCMP (Const Char*SRC,Const Char*DST) { -     intRET =0; the  -      while(! (ret = (* (unsignedChar*) src-* (unsignedChar*) (DST)) && *DST) -++SRC, + +DST; -      +     if(Ret <0) -RET =-1; +     Else if(Ret >0) ARET =1; at      -     returnret; - } -  - #endif

Main

1#include"Strcmp.h"2 3 4 voidtest_strcmp ();5 6 intMain () {7 test_strcmp ();8 9     return 0;Ten } One  A voidtest_strcmp () { -     Char*S1 ="Compare", *s2 ="Compase"; -printf"%d\n", cat_strcmp (S1, S2)); the  -     Char*S3 ="Compare", *S4 ="Compar"; -printf"%d\n", CAT_STRCMP (S3, S4)); -  +     Char*S5 ="Compar", *S6 ="Compare"; -printf"%d\n", CAT_STRCMP (S5, S6)); +  Aprintf"%d\n", CAT_STRCMP (S3, S6)); at}

/**
Expand:
unsigned char and char:
Http://blog.sina.com.cn/s/blog_5c6f793801019oij.html
http://blog.csdn.net/world7th/article/details/1543575
*/

C Language Implementation strcmp

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.