题解 | #字符串连接#
字符串连接
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; }