Skip to content

Commit

Permalink
Fix some programs
Browse files Browse the repository at this point in the history
  • Loading branch information
Babkock committed Nov 3, 2023
1 parent f2df265 commit 195ce8b
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions io/copy.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* File copier by Tanner Babcock
* January 11, 2012 */
* January 11, 2012,
* updated November 2, 2023 */
#include <iostream>
#include <fstream>
using namespace std;
Expand All @@ -9,23 +10,26 @@ int main(int argc, char *argv[]) {
cerr << "USAGE: " << argv[0] << " [inputfile] [outputfile]" << endl;
return 1;
}
// ifstream in(argv[1]);
ifstream in;
in.open(argv[1]);

ifstream *in = new ifstream();
in->open(argv[1]);

if (!in) {
cerr << "ERROR: Input file does not exist" << endl;
return 2;
}
// ofstream out(argv[2]);
ofstream out;
out.open(argv[2]);

ofstream *out = new ofstream();
out->open(argv[2]);

char x;
while (in.get(x))
out.put(x);
while (in->get(x))
out->put(x);

out.close();
in.close();
out->close();
in->close();
delete out;
delete in;
return 0;
}

0 comments on commit 195ce8b

Please sign in to comment.