实现strcmp非常easy的思维

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
void strcom(char *str1 , char *str2,int *num)
{
	int a = 0;
	int count = 0;
	//关键在这里 用指针进行循环推断
	while (*str1&&*str2)
	{
		str1++;
		str2++;
		if ((a=*str1 - *str2) != 0)
		{
			*num = a;
			return;
		}
	}
}
void main()
{ 
	char *str1 = "abdda";
	char *str2 = "abdd";
	int result = 0;
	strcom(str1, str2, &result);

	//推断假设 result 假设大于0的话 str1大于str2 否则 str1小于str2   等于0的话 两个字符串相等
	if (result > 0)
	{
		printf("");
	}
	system("pause");
}

posted @ 2016-01-02 15:05  phlsheji  阅读(176)  评论(0编辑  收藏  举报