REVERSEARGS.CPP Write the program reverseArgs.cpp that takes command line input
ID: 3592830 • Letter: R
Question
REVERSEARGS.CPP Write the program reverseArgs.cpp that takes command line input arguments and prints them back in reverse order. For example, if you ran the program as ./reverseArgs first_arg second_arg, you would get an output back of second_arg first_arg. If you ran the program as ./reverseArgs I love gorgonzola cheese, but I hate toothpaste, you would get an output back of toothpaste hate I but cheese, gorgonzola love I. This is why I (lovingly) refer to this exercise as "the Yoda program"... If you ran the program with double quotes, then the words within should act as one unit. For example: ./reverseArgs I would rather be at "UC Santa Barbara" would output: uc Santa Barbara at be rather would I REQUIREMENTS: You are only permitted to use the iostream libraryExplanation / Answer
#include<iostream>
#include<string.h>
#include<string>
using namespace std;
int main(int argc, char **argv){
string s[20];
for (int i= argc-1; i>0; i--){
cout << argv[i] << " ";
}
cout << endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.