
请我解释一下,下面的c++程序中,每句的含义
编写一个函数将两个字符串连接起来,不允许使用strcat函数。intcombine(char,char){chars1[80],s2[80];inti=0,j=0;whi...
编写一个函数将两个字符串连接起来,不允许使用strcat函数。
int combine(char,char)
{
char s1[80],s2[80];
int i=0,j=0;
while (s1[i]!='\0')
{i++;
while(s2[j]!='\0')
{s1[i++]=s2[j++];
s1[i]='\0';}
}
cout<<"the new stringis:"<<s1<<endl;
return 0;
} 展开
int combine(char,char)
{
char s1[80],s2[80];
int i=0,j=0;
while (s1[i]!='\0')
{i++;
while(s2[j]!='\0')
{s1[i++]=s2[j++];
s1[i]='\0';}
}
cout<<"the new stringis:"<<s1<<endl;
return 0;
} 展开
展开全部
int combine(char,char)
{
char s1[80],s2[80]; //定义两个字符数组
int i=0,j=0; //常数i,j 遍历数组使用
while (s1[i]!='\0') //判断是否执行到了数组s1的末尾,算出s1长度i
{i++; //这里应该是{i++;}
while(s2[j]!='\0') //当执行到s2末尾的时候停止
{s1[i++]=s2[j++]; // 这里应该是{s1[i++]=s2[j++];},依次把数组s2里面的字符接到s1后面
s1[i]='\0';} // }多余的 删掉,把连接后的字符串末尾加上一个串尾结束标志'\0'
} // 多余的} 删掉
cout<<"the new stringis:"<<s1<<endl; 输出连接后的字符串
return 0; 正常返回
}
程序大体没问题 但是两个} }的位置错了
{
char s1[80],s2[80]; //定义两个字符数组
int i=0,j=0; //常数i,j 遍历数组使用
while (s1[i]!='\0') //判断是否执行到了数组s1的末尾,算出s1长度i
{i++; //这里应该是{i++;}
while(s2[j]!='\0') //当执行到s2末尾的时候停止
{s1[i++]=s2[j++]; // 这里应该是{s1[i++]=s2[j++];},依次把数组s2里面的字符接到s1后面
s1[i]='\0';} // }多余的 删掉,把连接后的字符串末尾加上一个串尾结束标志'\0'
} // 多余的} 删掉
cout<<"the new stringis:"<<s1<<endl; 输出连接后的字符串
return 0; 正常返回
}
程序大体没问题 但是两个} }的位置错了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询