TXT文件去除多余空行

时间:2023-03-08 19:10:01
TXT文件去除多余空行

  有的小说段落之间有大批的空行,看起来十分难看,比如:

TXT文件去除多余空行

  长达500多页,手动改就尴尬了,废话不多少,直接上代码:

#include "stdafx.h"
#include <stdio.h>
int main() {
FILE * infile, * ofile;
errno_t erri = fopen_s(&infile, "input.txt", "r");
errno_t erro = fopen_s(&ofile, "output.txt", "w");
char ch[];
int ptr = ;
ch[ptr] = fgetc(infile);
while(ch[ptr] != EOF) {
if(ch[ptr] == '\n') {
if(ch[ - ptr] == '\n') {}
else {
fputc(ch[ptr], ofile);
}
} else {
fputc(ch[ptr], ofile);
}
ptr = - ptr;
ch[ptr] = fgetc(infile);
}
return ;
}

把生成的TXT另存为PDF,这样就好看多了:

TXT文件去除多余空行