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[2];
    int ptr = 0;
    ch[ptr] = fgetc(infile);
    while(ch[ptr] != EOF) {
        if(ch[ptr] == '
') {
            if(ch[1 - ptr] == '
') {}
            else {
                fputc(ch[ptr], ofile);
            }
        } else {
            fputc(ch[ptr], ofile);
        }
        ptr = 1 - ptr;
        ch[ptr] = fgetc(infile);
    }
    return 0;
}

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

原文地址:https://www.cnblogs.com/dramstadt/p/5887088.html