/***************************************************************************
 *  Columbia University Introduction to Computer Programming in C COMS 1003
 *  Program that Echos Command Line Arguments
 *
 *  Copyright (C) 2005 Michael E. Locasto
 *
 *  All rights reserved.
 *
 * $Id: echoargs.c,v 1.1 2005/09/21 20:00:26 locasto Exp $
 **************************************************************************/

#include <stdio.h>

/**
 * This program echos the arguments supplied in argv.
 *
 * The 'argc' parameter tells the program how many arguments there
 * are and is set up for the program by the operating system. 'argc'
 * is usually at least equal to 1, because the value in argv[0[ is
 * the name of the binary that this program is executing as.
 * 
 * Incidently, this program also illustrates the use of the ternary
 * operator and the for() loop. You will learn more about these next
 * week.
 *
 * Sample output is:
 *
[michael@xoren code]$ ./echoargs you me michael 2 4 5.66 -s --start --version
This program was called with 10 arguments.
The name of this program is [./echoargs]
argv[0] = ./echoargs
argv[1] = you
argv[2] = me
argv[3] = michael
argv[4] = 2
argv[5] = 4
argv[6] = 5.66
argv[7] = -s
argv[8] = --start
argv[9] = --version
[michael@xoren code]$ 
 * 
 */
int main(int argc, char* argv[])
{
   int counter = 0;

   printf("This program was called with %d argument%c.\n", argc, 
          (argc==1?'\0':'s'));
   printf("The name of this program is [%s]\n", argv[0]);

   /* Counter will increase in value from 0 to whatever is in 'argc'*/
   for(counter=0;counter<argc;counter++)
   {
      /* At each step, print current value of argv[]*/
      printf("argv[%d] = %s\n", counter, argv[counter]);
   }
   /* bookkeeping */
   return 0;
}
