[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;
}