填空题
以下程序的功能是:实现两个字符串拼接,函数strcat(char *s1,char *s2)先将s1所指向的字符串拷贝到s所指向的动态申请的存储空间,接着将s2所指向的字符串拼接s所指向的字符串后面,函数返回拼接后的字符串。
[程序](4分)
#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(23) 2 ;
p=s1;
for(int i=0;i3(24) 4);
5(25) 6
}
void main(void)
{
char s1[]="visual";
char s2[]="is esay";
char *s;
s= 7(26) 8;
cout<
【正确答案】
1、(23)new char[len1+len2+1]
(24)*q++=*p++
(25)return s
(26)strcat(s1,s2)
【答案解析】