summaryrefslogtreecommitdiff
path: root/reference/C/CONTRIB/SNIP/cmdline.c
blob: d46da835f604990c0da222e6057107201b4ca4b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
**  CMDLINE.C - Demonstrates accessing command line arguments
*/

#include <stdio.h>

#define plural_text(n) &"s"[(1 == (n))]
#define plural_text2(n) &"es"[(1 == (n)) << 1]

main(int argc, char *argv[])
{
      int i, n = argc - 1;

      printf("You passed %d argument%s on the command line.",
            n, plural_text(n));

      if (argc > 1)
      {
            puts(" They are:");
            for (i = 1; i < argc; ++i)
            {
                  printf("\nArgument #%d:\n  Text: \"%s\"\n  Value: %d\n",
                        i, argv[i], atoi(argv[i]));
            }
      }
      else  putchar('\n');
      return 0;
}