字符串之strcmp

功能:比较两个字符串的ascII码大小

输入:两个字符串

返回值:相等为0,大于为大于零,小于为小于零

#include <iostream>
#include <assert.h>
using namespace std;
int _strcmp(const char *str1,const char *str2)
{
	assert((str1 != NULL)&&(str2 != NULL));
	while (*str1 && *str2 && *str1 == *str2)
	{
		str1++;
		str2++;
	}
	return *str1- *str2;
}
int main()
{
	const char *str1 = "abcdef";
	const char *str2 = "aBe";
	cout << _strcmp(str1,str2)<<endl;
	return 0;
};

 

posted @ 2013-08-23 22:35  l851654152  阅读(221)  评论(0编辑  收藏  举报