sun4lower
3/16/2018 - 9:46 AM

The arguments of main function in C.

Print each of the input parameters of the main function.

#include <stdio.h>

int main(int argc, char *argv[])
{
  int i;
  for(i = 0; i < argc; i++) {
    printf("argv[%d] is %s", i, argv[i]);
  }
  return 0;
}

// ./main.out -l -a -t will output:
/**
 * ./main.out -l -a -t will output:
 * argv[0] is ./main.out
 * argv[1] is -l
 * argv[2] is -a
 * argv[3] is -t
 */