codeup|问题 A: 字符串连接

题目描述
不借用任何字符串库函数实现无冗余地接受两个字符串,然后把它们无冗余的连接起来。

输入
每一行包括两个字符串,长度不超过100。

输出
可能有多组测试数据,对于每组数据,
不借用任何字符串库函数实现无冗余地接受两个字符串,然后把它们无冗余的连接起来。
输出连接后的字符串。

样例输入 Copy
abc def
样例输出 Copy
abcdef

代码

#include<stdio.h>

int main() {
    char str1[200], str2[100];
    while (scanf("%s %s", str1, str2) != EOF) {
        int len1 = 0, len2 = 0;
        while (str1[len1] != '\0') {
            len1++;
        }
        while (str2[len2] != '\0') {
            len2++;
        }
        for (int i = 0; i < len2; i++) {
            str1[i + len1] = str2[i];
        }
        for (int i = 0; i < len1 + len2; i++) {
            printf("%c", str1[i]);
        }
        printf("\n");
    }
    return 0;
}

注意点
一定要注意字符串结尾的标致是’\0’

猜你喜欢

转载自blog.csdn.net/weixin_43340821/article/details/113871857
今日推荐