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