字符串连接

题目截图:

 

思路:

  利用辅助数组,将两个字符串都复制到该数组中即可。

 

代码如下:

 

 1 /*
 2     字符串连接 
 3 */
 4 
 5 #include <stdio.h>
 6 #include <string.h>
 7 #include <math.h>
 8 #include <stdlib.h>
 9 #include <time.h>
10 #include <stdbool.h>
11 
12 int main() {
13     // 将str1和str2拼接到str3 
14     char str1[101], str2[101], str3[202]; 
15     scanf("%s %s", str1, str2);
16     int i, j;
17     for(i=0; i<strlen(str1); ++i) {        // 先复制str1 
18         str3[i] = str1[i];
19     }
20     for(j=0; j<strlen(str2); ++j) {        // 后复制 str2 
21         str3[i++] = str2[j];
22     }
23     str3[i] = '\0';                        // 字符串末尾 
24     printf("%s", str3);                    // 输出字符串 
25 
26     return 0;
27 }

 

转载于:https://www.cnblogs.com/coderJiebao/p/HustTest05.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值