Write the program reverseArgs.cpp that takes command line input arguments and pr
ID: 3830158 • Letter: W
Question
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. You are only permitted to use the iostream library. A session should look exactly like the following example (including whitespace and formatting note that there is no whitespace at the end of each of these lines and each printed line has a newline at the end), with all manners of different numbers for inputs and the output: /reverseArgs ./reverse Args Hello Hello /reverseArgs Hello is it me me it is Hello ./reverse Args Hello is it me "you're looking for?" you're looking for? me it is Hello ./reverse Args You Are Not a Jedil Jedi a Not Are YouExplanation / Answer
#include <stdio.h>
int main(int argc, char *argv[])
{
while (argc-- > 0)
printf("%s ", argv[argc]);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.