/*
?* 字符串比较大小(类似于String的CompareTo()方法)
?*/
#include<stdio.h>
#include<stdlib.h>
int compare(const char *s1,const char *s2)
{
?while(*s1!='\0'&&s2!='\0')
?{
??if(*s1==*s2)
??{
???s1++;
???s2++;
??}
??else if(*s1>*s2)
??{
???return 1;
??}
??else
??{
???return -1;
??}
?}
?if(*s1=='\0'&&*s2=='\0')return 0;
?else if(*s1!='\0'&&*s2=='\0')return 1;
?else return -1;
}
int main()
{
?const char *s1="abc";
?const char *s2="abc";
?int result=compare(s1,s2);
?printf("result=%d\n",result);
?return 0;
}