/* * ECHO -- print arguments followed by a newline * * Usage: echo arg1 arg2 ... argn * * Inputs: none * Outputs: the arguments except for the 0th (which is the program name), * separated by a blank, and with a newline at the end * Exceptions: if no arguments beyond the program name, do not output a newline * Exit Code: EXIT_SUCCESS * * Matt Bishop, ECS 36A, Fall 2019 * * Oct. 22, 2015 -- original program written * Oct. 23, 2019 -- modified for ECS 36A */ #include #include /* * print arguments followed by a newline */ int main(int argc, char *argv[]) { int i; /* counter in a for loop */ /* * go through the argument list, skipping arg 0 (it's * the program name) */ for(i = 1; i < argc-1; i++) printf("%s ", argv[i]); /* * now print the last argument, UNLESS it is arg 0 */ if (argc > 1) printf("%s\n", argv[argc-1]); /* * return success! */ return(0); }