c++高手速度来,给你分

来源:百度知道 编辑:UC知道 时间:2024/05/04 15:30:44
将字符串b连接到字符串a。但程序中存在若干错误,请你纠正。

#include<stdio.h>
void main( )
{ char a[]="wel",b[]="come";
int i,n=0;
while(!a[n]) n++;
for(i=0;b[i]!='\0';i++)
a[n+i]=b[i];
printf("%s\n",a);
}
就是个改错,不用那个 strcat .我们没讲那个呢还!!!在线等,速度!!!

#include<stdio.h>
void main( )
{ char a[100]="wel",b[]="come"; //a必须要有足够的空间
int i,n=0;
while(a[n]) n++; //条件写反了
for(i=0;b[i]!='\0';i++)
a[n+i]=b[i];
printf("%s\n",a);
}

#include <stdio.h>

char* Strcat(char *str1,char *str2)
{
char* tempt = str1;

while(*str1!='\0')
{
str1++;
}

while(*str2!='\0')
{
*str1 = *str2;
str1++;
str2++;
}

*str1 = '\0';
return tempt;
}

int main()
{
char a[20] = "hello";
char b[20] = ",everyOne!";
printf("%s",Strcat(a,b));
}

用strcat
#include<iostream>

int main()
{
char a[]="wel",b[]="come";
printf("%s\n",strcat(a,b));
r