Fix multiple file args
With multiple files, you would get a line for each file argument, but only from the first file, never from any other file argument.
This commit is contained in:
@@ -70,7 +70,7 @@ int main(int argc, char* argv[]) {
|
|||||||
for (int i = optind; i < argc; ++i) {
|
for (int i = optind; i < argc; ++i) {
|
||||||
try {
|
try {
|
||||||
// process file argv[i]
|
// process file argv[i]
|
||||||
ifstream infile {argv[1]};
|
ifstream infile {argv[i]};
|
||||||
cout << random_line_from_file(infile) << '\n';
|
cout << random_line_from_file(infile) << '\n';
|
||||||
} catch (const runtime_error& ex) {
|
} catch (const runtime_error& ex) {
|
||||||
cerr << "ranlin: " << ex.what() << '\n';
|
cerr << "ranlin: " << ex.what() << '\n';
|
||||||
|
Reference in New Issue
Block a user