3.3 Exercise 3: Echo In this exercise write a C/C++ program that will echo back to the terminal the input given to the p
Posted: Tue Jul 12, 2022 8:10 am
3.3 Exercise 3: Echo In this exercise write a C/C++ program that will echo back to the terminal the input given to the program. You can learn more about echo by typing man echo into a terminal. This exercise will help you learn to work with command line arguments. Remember the function prototype for C/C++ is int main (int argc, char* argv[]); or int main(int argc, char** argv); where argc is the number of arguments and argv is a pointer to an array of pointers (remember C has no notion of strings). Each member of the array points to the characters in each argument to the program. A representation of this can be seen here z123456@turing:~$ myprog dog cat frog [0] [1] [2] [3] argv . ▸ d ● ● arge C f Y Р r 0 g 10 a r t 10 。 g 10 2 0 g 10 You can read more about it by googling "arge and argv in C." At this point you just need to parse the arguments and print them back to the terminal. A for loop should do the job nicely.