字符串的交叉合并问题;如,输入两个字符串,要求将这两个字符串交叉连接。如串1为"ABCD",串2为
发布网友
发布时间:2022-05-08 16:47
我来回答
共1个回答
热心网友
时间:2024-01-25 23:10
#include <stdio.h>
const size_t MAXSIZE = 100;
char *merge(char s[], char t[]) {
int i = 0,j = 0;
char c[MAXSIZE];
while(s[i] && t[i]) {
c[j++] = s[i];
c[j++] = t[i];
++i;
}
while(s[i]) c[j++] = s[i++];
while(t[i]) c[j++] = t[i++];
c[j] = '\0';
i = 0;
while(s[i] = c[i]) ++i;
return s;
}
int main() {
char s[MAXSIZE] = "ABCDEFGHI";
char t[] = "12345";
printf("%s\n",merge(s,t));
return 0;
}