由键盘任意输入两个字符串,连接字符串2到字符串1,输出连接后的字符串1
来源:百度知道 编辑:UC知道 时间:2024/05/25 12:34:33
不用到strcat函数和指针,用数组和循环语句知识写,谢谢!
/*由键盘任意输入两个字符串,连接字符串2到字符串1,输出连接后的字符串1*/
#include <stdio.h>
int main(int argc, char *argv[])
{
int i, j = 0;
char s1[100];
char s2[100];
printf("Enter s1:");
scanf("%s", s1);
printf("Enter s2:");
scanf("%s", s2);
for(i = strlen(s1); j <= strlen(s2); i++)
{
s1[i] = s2[j++];
}
printf("result:%s\n", s1);
return 0;
}