首页 > 其他 > 详细

字符串连接

时间:2018-02-06 17:12:33      阅读:166      评论:0      收藏:0      [点我收藏+]

题目截图:

技术分享图片

 

思路:

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

 

代码如下:

 

 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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!