Download this source file


/* Parrot.c - A program to print its command line arguments to stdout.
 * This program accepts one optional argument: "-n" will cause the output
 * to appear with one command line argument per line.
 * Note optional arguments preceed regular (required) arguments.
 *
 * Written 2001 by Wayne Pollock, Tampa Florida USA.
 */

#include <stdio.h>
#include <string.h>

int main ( int argc, char* argv[] )
{
   int i = 1;             /* i is the index of 1st cmd line arg to print. */
   char sep_char = ' ';   /* separater; either a space or a newline. */

   if ( argc >= 2 && strcoll( argv[1], "-n" ) == 0 )
   {
      sep_char = '\n';
      ++i;
   }
   for ( ; i < argc; ++i )
   {
      printf( "%s%c", argv[i], sep_char );
   }
   if ( sep_char == ' ' )
      printf( "\n" );    /* end the single line of output with a newline. */
   return 0;
}




Send comments and mail to pollock@acm.org.