字符串比较

一、代码

 1 //字符串比较
 2 #include <iostream>
 3 using namespace std;
 4 int mystrcmp(char s1[],char s2[])
 5 {
 6     int i=0;
 7     while(s1[i]==s2[i]&&s1[i]!=0&&s2[i]!=0)
 8         i++;
 9     int m=s1[i]-s2[i];
10     if(m<0)
11         cout<<"string1 is shorter than string2 at "<<m<<endl;
12     if(m==0)
13     cout<<"string1 is equal as string2 at "<<m<<endl;
14     if(m>0)
15     cout<<"string1 is longer than string2 at "<<m<<endl;
16     return 0;
17 }
18 void main()
19 {
20 
21     char a[20],b[20];
22     cout<<"Please input the string 1:"<<endl;
23     cin>>a;
24     cout<<"Please input the string 2:"<<endl;
25     cin>>b;
26     mystrcmp(a,b);
27 }

二、运行

原文地址:https://www.cnblogs.com/f59130/p/3328381.html