Examples of parsing command line parameters in C language
argc :The number of parameters (including the name of the program itself)
argv: parameters list
example.c
/* parse parameter in command line using c: */ #include <stdio.h> int main(int argc, char **argv) { for (int i = 0; i < argc; ++i) { printf("argv[%d]: %s\n", i, argv[i]); } }
compile:
$ gcc example.c
run:
$ ./a.out hello lautturi 123 argv[0]: ./a.out argv[1]: hello argv[2]: lautturi argv[3]: 123