主题:实现函数strcal功能。。结果不对
程序实现strcal功能(s2追加到s1之后)结果出错。帮忙看看???
#include<iostream.h>
char *strcal(char *s1,const char *s2);
int main()
{char s1[]="ABCDE";
const char s2[]="ABCDEFG";
char *p=strcal(s1,s2);
for(;*p;p++)
{
cout<<*p;
}
cout<<endl;
return 0;
}
char *strcal(char *s1,const char *s2)
{char *p;
for(p=s1;*p;p++);
for(;*s2;s2++,p++)
{
*p=*s2;
}
*p='\0';
return s1;
}
#include<iostream.h>
char *strcal(char *s1,const char *s2);
int main()
{char s1[]="ABCDE";
const char s2[]="ABCDEFG";
char *p=strcal(s1,s2);
for(;*p;p++)
{
cout<<*p;
}
cout<<endl;
return 0;
}
char *strcal(char *s1,const char *s2)
{char *p;
for(p=s1;*p;p++);
for(;*s2;s2++,p++)
{
*p=*s2;
}
*p='\0';
return s1;
}