01-logic_syntax_bugs.c 860 Bytes
Newer Older
Xavier Besseron's avatar
PS 2021  
Xavier Besseron committed
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>

// This program lists the arguments it has been called with.
//
// Examples of usage:
//
//   ./01-logic_syntax_bugs
//   ./01-logic_syntax_bugs param1
//   ./01-logic_syntax_bugs param1 2
//   ./01-logic_syntax_bugs param1 2 testParam
//


int main(int argc, char** argv)
{
  // number of parameters
  int nb_params = argc - 1;

  // first print a message
  if ( nb_params > 1 )
  {
    printf("This program was called with %i parameters\n", nb_params);
  }
  else if ( nb_params = 1 )
  {
    printf("This program was called with only 1 parameter\n");
  }
  else
  {
    printf("This program was called without any parameter\n");
  }

  // print program name and all parameters
  printf("program = '%s'\n", argv[0] );
  int i;
  for ( i = 0 ; i < nb_params ; i++ )
  {
    printf("parameter %i = '%s'\n", i, argv[i] );
  }

  return 0;
}