目录
代码1
代码2
代码3
代码1
#include代码2int main(void) { char str1[50], str2[50], str3[100]; gets(str1); gets(str2); int i, j; for(i = 0, j = 0; str1[i] != '' && str2[i] != ''; i++) { str3[j++] = str1[i]; str3[j++] = str2[i]; } while(str1[i] != '') str3[j++] = str1[i++]; while(str2[i] != '') str3[j++] = str2[i++]; str3[j] = ''; printf("%s", str3); return 0; }
#include代码3void str_add(char* a, char* b){ int i=0; while(a[i] && b[i]) { printf("%c%c", a[i], b[i]); i++; } if(a[i]) printf("%sn", a+i); if(b[i]) printf("%sn", b+i); } int main(){ str_add("abcd", "ABCDEFG"); str_add("ABCDEFG","abcd"); }
#define _CRT_SECURE_NO_WARNINGS #include#include void Merge(char a[], char b[], char c[]){ int len1, len2; len1 = strlen(a); len2 = strlen(b);//c中没有max函数,一般比较大小时会自己定义一个函数max int i = 0, j = 0, k = 0, max = len1 > len2 ? len1 : len2; for (i = 0; i < max; i++) { if (i < len1) { //printf("%c", a[i]); c[k++] = a[i]; } if (j < len2) { //printf("%c", b[j++]); c[k++] = b[j++]; } } puts(c); } int main() { char str1[50], str2[50], str3[100]; gets(str1); gets(str2); //puts(str1); //puts(str2); Merge(str1, str2, str3); //puts(str3); return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)