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

把生成的TXT另存為PDF,這樣就好看多了:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM