/*This program reads an ASCII file specified by the user and writes the resulting numeric code for picint to picint.dat*/ #include #include #include main() { /********************** *initialize variables* **********************/ char symbol, current_symbol = '*', in_filename[16]; int counter; ofstream out_stream; ifstream in_stream; /************ *Open files* ************/ out_stream.open("picint.dat"); if (out_stream.fail()) { cout << "Error opening output file"; exit(1); } cout << "Specify an input file: "; cin >> in_filename; in_stream.open(in_filename); if (in_stream.fail()) { cout << "Error opening input file"; exit(1); } /*************** *Compute away!* ***************/ in_stream.get(symbol); while (1) { if (symbol == ' ') { counter = 0; do { counter++; in_stream.get(symbol); } while (symbol == ' '); out_stream << "0 " << counter << " "; } if (symbol == 10) { out_stream << "-1 0 "; in_stream.get(symbol); } if (symbol != ' ' && symbol != 10) { if (symbol != current_symbol) { out_stream << "-3 " << static_cast(symbol) << " "; current_symbol = symbol; } counter = 0; do { counter++; in_stream.get(symbol); } while (symbol == current_symbol); out_stream << counter << " "; if (symbol == ' ') { counter = 0; do { counter++; in_stream.get(symbol); } while (symbol == ' '); out_stream << counter << " "; } else out_stream << "0 "; } if (in_stream.eof()) break; } out_stream << "-2 0"; /**************** *Finish program* ****************/ in_stream.close(); out_stream.close(); cout << "picint.dat written successfully!"; return 0; }