[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

CR/LF even better



#include <fstream.h>
#include <queue>

using namespace std;

void process_file(int argc, char **argv);
void process_stdin();
void check_char(char &ch);

int main(int argc, char **argv)
{
    if(argc > 1)
        process_file(argc, argv);
    else
        process_stdin();
    return 0;
}

void process_file(int argc, char **argv)
{
    char ch;
    queue<char> tmp_q;
    ifstream infile;
    ofstream outfile;

    for(int count=1; count < argc; ++count){
        infile.open(argv[count]);
        if(!infile){
            cerr << "error opening input " << argv[count] << endl;
            exit(1);
        }
        while(!infile.eof()){
            infile.get(ch);
            switch(ch){
            case '\r':
                break;
            default:
                tmp_q.push(ch);
            }
        }
        infile.close();

        outfile.open(argv[count]);
        if(!outfile){
            cerr << "error opening output " << argv[count] << endl;
            exit(2);
        }
        while(!tmp_q.empty()){
            outfile.put(tmp_q.front());
            tmp_q.pop();
        }
        outfile.close();
    }
}

void process_stdin()
{
    char ch;

    while(!cin.eof()){
        cin.get(ch);
        switch(ch){
        case '\r':
             break;
        default:
            cout << ch;
        }
    }
}



Reply to: