奔跑的小河
Talk is cheap. Show me the code.

导航

 
//这是系统库的实现
int strcmp(const char* src, const char* dest)
{
	int rtn = 0;
	while(!(rtn = *(unsigned char*)src - *(unsigned char*)dest) && *dest)
	{
		++src;
		++dest;
	}
	if (rtn < 0)
	{
		rtn = -1;
	}else if (rtn > 0)
	{
		rtn = 1;
	}
	return rtn;
}


结果:相等返回0,src 大于dest返回1,src小于dest返回-1.。

posted on 2015-06-27 10:37  奔跑的小河  阅读(125)  评论(0编辑  收藏  举报