//对每一个字符逐步进行比较
#include<stdio.h>
#include <assert.h>
int my_strcmp(const char *p,const char *q)
{
assert(p!=NULL);//断言,括号内假就退出
assert(q!=NULL);
int i = 0;
for(;q[i]== p[i];i++)
{
if('\0'== q[i])//其实判断条件为'\0'==p[i]也行
{
return 0;
}
if((p[i]-q[i])>0)
{
return 1;
}
else
{
return -1;
}
}
}
int main( void )
{
char string[20]="1";//非数字字符串也行
char S_string[20]="123456";
printf("%d\n", my_strcmp( string,S_string ));
return 0;
}