不用你写的那么复杂的,不需要用到数组,更不需要用二维数组。运行不出来,多数是你用了C编译器,我那代码又没什么高深的语句,都是很基本的函数(fopen_s()函数不熟悉可以用回fopen(),打开的文件指针是一样的)。
授人以渔,不授人以鱼。
#include <stdio.h> int wF1(FILE *fpN, FILE *fp) { char c; while((c = fgetc(fp)) != '\n') { if(c == EOF) return 0; fputc(c, fpN); } return 1; } int wF2(FILE *fpN, FILE *fp) { char c; while((c = fgetc(fp)) != EOF) { fputc(c, fpN); if(c == '\n') { return 1; break; } } if(c == EOF) fprintf(fpN, "\n"); return 0; } int main(void) { int flag = 1; FILE *fp1 = fopen("1.txt", "r"); FILE *fp2 = fopen("2.txt", "r"); FILE *fpN = fopen("new.txt", "w+"); if(!fp1 || !fp2 || !fpN) return 1; while(flag) { flag = wF1(fpN, fp1); while(wF2(fpN, fp2)) { if(!feof(fp1)) fseek(fp1, -6L, 1); else fseek(fp1, -4L, 1); wF1(fpN, fp1); } rewind(fp2); } fclose(fp1); fclose(fp2); fclose(fpN); return 0; }