分享一下
#include<iostream.h>void str_cat(char *p1,char *p2)
{
while(*p1++);
p1--;
while(*p1++=*p2++);
}
int str_len(char *p)
{
int i=0;
while(*p++)
i++;
return i;
}
int str_cmp(char *p1,char *p2)
{
while(*p1=*p2&&*p1!=0&&*p2!=0)
{
// if(*p1>*p2)
//return 1;
//else if(*p1<*p2)
//return -1;
p1++;
p2++;
}
if(*p1>*p2)
return 1;
else if(*p1<*p2)
return -1;
return 0;
}
void main()
{
char s1[5],s2[5],*str1,*str2;
str1=s1;
str2=s2;
cout<<"Input first string:\n";
cin.getline(str1,5);
cout<<"input send string:\n";
cin.getline(str2,5);
str1=s1;
str2=s2;
str_cat(str1,str2);
cout<<"s1="<<str1<<endl;
cout<<str_cmp(str1,str2)<<endl;
}