#include <cstdlib>
#include <iostream>
using namespace std;
Create a program that reads from the file specified by a command line argument, then writes out the contents reversed line-by-line to a separate file specified on the command line. For example, the user enters on the the commandline: reverse -i input.txt -o myoutput.txt. Your program must search the command line argument list given by the main program parameters, argc and argv. The commandline arguments may be specified in any order, though the file names will always be found immediately adjacent to the -i or -o switch.Code:int main(int argc, char *argv[] ) { cout << "argc is: " << argc << endl; if (argc >= 1) cout << "This program was run as: " << argv[0] << endl; if (argc > 1) { cout << "This program received the following arguments:" << endl; for (int i = 1; i < argc; i++) cout << "\t" << argv[i] << endl; } cin.get(); return 0; }
Your program must:
1.Search the command line arguments for input and output file names.
2.Open the input and output files, displaying an appropriate error message on open file errors
3.Read the input file line-by-line into a 256-character C-string buffer using fgets() or the iostream getline() member function, then write out the line to the output file.
4.Close both files and end the program
The above code is what I've done so far. However, I don't know how to run this on command prompt. Please help. I'd appreciate it.