/*
* 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
*
* October 22, 2015
* -- original program written
* October 23, 2019
* -- modified for ECS 36A
*/
#include <stdio.h>
#include <stdlib.h>
/*
* 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);
}
|
ECS 36A, Programming & Problem Solving Version of April 2, 2024 at 12:13PM
|
You can get the raw source code here. |