以下是引用wp231957在2017-3-26 07:07:39的发言:
我给你看看微软工程师写的strcmp源码/*这里我摘录了函数的版权情况
*strcmp.c - routine to compare two strings (for equal, less, or greater)
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
* Compares two string, determining their lexical order.
*
*/
/* 这里我只摘录了函数的返回值
Exit:
* returns -1 if src < dst
* returns 0 if src == dst
* returns +1 if src > dst
*/
int __cdecl strcmp ( const char * src, const char * dst )
{
int ret = 0 ;
while( ! (ret = *(unsigned char *)src - *(unsigned char *)dst) && *dst) ++src, ++dst;
if ( ret < 0 ) ret = -1 ;
else if ( ret > 0 ) ret = 1 ;
return( ret );
}
我给你看看微软工程师写的strcmp源码/*这里我摘录了函数的版权情况
*strcmp.c - routine to compare two strings (for equal, less, or greater)
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
* Compares two string, determining their lexical order.
*
*/
/* 这里我只摘录了函数的返回值
Exit:
* returns -1 if src < dst
* returns 0 if src == dst
* returns +1 if src > dst
*/
int __cdecl strcmp ( const char * src, const char * dst )
{
int ret = 0 ;
while( ! (ret = *(unsigned char *)src - *(unsigned char *)dst) && *dst) ++src, ++dst;
if ( ret < 0 ) ret = -1 ;
else if ( ret > 0 ) ret = 1 ;
return( ret );
}
学习了
考虑扩展码部分output()要修改为:
int output(char *str1, char *str2)
{
for (; *str1==*str2 && *str1 && *str2; str1++,str2++) NULL;
return *(unsigned char *)str1 - *(unsigned char *)str2;
}