题解 | #字符串连接#

字符串连接

https://www.nowcoder.com/practice/40d83e5509b04d20825ae68fe35e9ca8

#include <stdio.h>
#define MAX 101
int main() {
    char str1[MAX], str2[MAX];
    while (scanf("%s %s", &str1, &str2) != EOF) { // 注意 while 处理多个 case
        char s[2*MAX];
        int i = 0,j = 0;
	  //先把str1的字符存入到s字符数组中
        while (str1[i] != '\0'){
            s[j++] = str1[i++];
        }
        i = 0;//i重新置0
	  //再将str2的字符接到s数组后面
        while (str2[i] != '\0'){
            s[j++] = str2[i++];
        }
        s[j] = '\0';	//s尾 置字符串结束符\0
        printf("%s\n", s);
    }
    return 0;
}

全部评论

相关推荐

点赞 评论 收藏
分享
程序员饺子:正常 我沟通了200多个 15个要简历 面试2个 全投的成都的小厂。很多看我是27直接不会了😅
点赞 评论 收藏
分享
码农索隆:想看offer细节
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务