字符串比较

#include<stdio.h>

int strcmpr(const char*, const char*);

int main()
{
	char A[]="abcd";
	char B[]="abcd";
	int result = strcmpr(A,B);
	printf("result=%d\n",result);
	return 0;
}

int strcmpr(const char *str1, const char *str2)
{
	int cnt = 0;
	if(*str1 == NULL || *str2 == NULL)
	{
		return -1;
	}
	while(*str1 != NULL && *str2 != NULL)
	{
		if(*str1 == *str2)
		{
			str1++;
			str2++;
			cnt++;
		}
		else
		{
			return cnt;
		}
	}
	if(*str1 == NULL && *str2 == NULL)
	{
		return 0;
	}
	else
	{
		return cnt;
	}
}

 

posted @ 2014-05-11 23:16  米其林轮船  阅读(103)  评论(0编辑  收藏  举报