运用freopen,快速简洁读写文件#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void merge(const char * m1, const char * m2) {
int m1len = strlen(m1 + 1);
int m2len = strlen(m2 + 1);
int m1p = 1, m2p = 1, tot = 0;
char r[20001] = {};
while (m1p <= m1len && m2p <= m2len) {
if (m1[m1p] < m2[m2p]) {
r[++tot] = m1[m1p++];
} else {
r[++tot] = m2[m2p++];
}
}
while (m1p <= m1len) r[++tot] = m1[m1p++];
while (m2p <= m2len) r[++tot] = m2[m2p++];
printf("%s", r + 1);
}
int main() {
freopen("m1.txt", "r", stdin);
char m1[10001] = {}, m2[10001] = {};
fgets(m1 + 1, 10000, stdin);
m1[strlen(m1 + 1)] = '\0';
freopen("m2.txt", "r", stdin);
fgets(m2 + 1, 10000, stdin);
m2[strlen(m2 + 1)] = '\0';
freopen("m3.txt", "w", stdout);
merge(m1, m2);
}
|