Skip to content

Commit

Permalink
I must delete before return
Browse files Browse the repository at this point in the history
  • Loading branch information
Babkock committed Nov 20, 2023
1 parent 6e87237 commit ee0e1bd
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions io/read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ int main(int argc, char *argv[]) {
if (argc > 1) {
ifstream *in = new ifstream[argc];
char y;

for (int x = 1; x < argc; x++) {
in[x-1].open(argv[x]);
if (!in[x-1]) {
Expand All @@ -22,10 +23,12 @@ int main(int argc, char *argv[]) {
delete[] in;
return 2;
}

while (in[x-1].get(y))
cout.put(y);
in[x-1].close();
}

delete[] in;
}
else if (argc == 1) {
Expand All @@ -34,14 +37,17 @@ int main(int argc, char *argv[]) {

if (!in) {
cerr << "ERROR: '" << argv[1] << "' File not found" << endl;
delete in;
return 2;
}

char x;
while (in->get(x)) // fails on EOF
cout.put(x);
in->close();
delete in;
}

return 0;
}

0 comments on commit ee0e1bd

Please sign in to comment.