以下程序的功能是:实现两个字符串拼接,函数strcat(char *s1,char *s2)先将s1所指向的字符串拷贝到s所指向的动态申请的存储空间,接着将s2所指向的字符串拼接s所指向的字符串后面,函数返回拼接后的字符串。
[程序]
#include
char *strcat(char *s1,char *s2)
{
char *s, *p, *q;
int len1=0,len2=0;
p=s1;
while(*p!=’\0’){
len1++;
p++;
}
p=s2;
while(*p!=’\0’){
len2++;
p++;
}
s=q=___(1)___ ;
p=s1;
for(int i=0;i
p=s2;
while(___(2)___);
___(3)___
}
void main(void)
{
char s1[]="visual";
char s2[]="is esay";
char *s;
s=___(4)___;
cout<
delete []s;
}
参考答案:
(1)new char[lenA+lenB+A]
(2)*q++=*p++
(3)return s
(4)strcat(sA,sB)