home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / SNIP9404.ZIP / CMDLINE.C < prev    next >
C/C++ Source or Header  |  1994-04-03  |  666b  |  29 lines

  1. /*
  2. **  CMDLINE.C - Demonstrates accessing command line arguments
  3. */
  4.  
  5. #include <stdio.h>
  6.  
  7. #define plural_text(n) &"s"[(1 == (n))]
  8. #define plural_text2(n) &"es"[(1 == (n)) << 1]
  9.  
  10. main(int argc, char *argv[])
  11. {
  12.       int i, n = argc - 1;
  13.  
  14.       printf("You passed %d argument%s on the command line.",
  15.             n, plural_text(n));
  16.  
  17.       if (argc > 1)
  18.       {
  19.             puts(" They are:");
  20.             for (i = 1; i < argc; ++i)
  21.             {
  22.                   printf("\nArgument #%d:\n  Text: \"%s\"\n  Value: %d\n",
  23.                         i, argv[i], atoi(argv[i]));
  24.             }
  25.       }
  26.       else  putchar('\n');
  27.       return 0;
  28. }
  29.