C语言模拟实现库函数strcmp

int  my_strcmp(const char* s1, const char* s2)
{
	assert(s1);
	assert(s2);
	while (*s1 == *s2&& *s1 != '\0' && *s2 != '\0')
	{
		s1++;
		s2++;
	}	
	return *s1 - *s2;
}
int main()
{
	char  s1[] = "abbc";
	char  s2[]= "abc";
	int ans = 0;
	 ans = my_strcmp(s1,s2);
	if (ans > 0)
		printf("s1>s2");
	else if(ans==0)
		printf("s1==s2");
	else 
		printf("s1<s2");
	return 0;
}

 

©️2020 CSDN 皮肤主题: 游动-白 设计师:上身试试 返回首页