一个简单的C语言编程问题

2025-01-20 10:51:19
推荐回答(2个)
回答1:

#include/*你用Turbo C吧,这是头文件,一定要记得,以后会用的*/
#include
void main()
{char a[6]="hello",b[6]="world",c[20];int i=0;
do{
c[i]=a[i];i++;
}while(a[i]!='\0');
i=0;
do{c[(i)+strlen(a)]=b[i];i++;/*strlen()函数是求字符串个数不包含'\0'字符,如题strlen(a)的值就为5*/
}while(b[i]!='\0');
c[strlen(a)+strlen(b)]='\0';
printf("%s",c);
}

回答2:

#include
#include

int main()
{
char *p = "Hello";
char *q = "World";
char together[20] = "";
strcat(together, p);
strcat(together, q);
printf("%s", together);
return 0;
}