用c语言连接两个字符串字符串用键盘输入。不调用函数
#include <stdio.h> #include <string.h>
int main() { char str1[100], str2[100], result[200]; int i, j;
printf("Enter the first string: ");
scanf("%s", str1);
printf("Enter the second string: ");
scanf("%s", str2);
// Copying the first string to the result array
for (i = 0; str1[i] != '\0'; i++) {
result[i] = str1[i];
}
// Concatenating the second string to the result array
for (j = 0; str2[j] != '\0'; j++) {
result[i + j] = str2[j];
}
// Null terminating the result array
result[i + j] = '\0';
printf("The concatenated string is: %s\n", result);
return 0;
}
原文地址: http://www.cveoy.top/t/topic/bk1o 著作权归作者所有。请勿转载和采集!