After receiving the arguments, you can print them as follows:
int main(int argc, char **argv)
{
for (int i = 1; i < argc; i++)
{
printf("Argument %d: [%s]\n", i, argv[i]);
}
}
Notes
argv
parameter can be also defined as char *argv[]
.argv[0]
may contain the program name itself (depending on how the program was executed). The first "real" command line argument is at argv[1]
, and this is the reason why the loop variable i
is initialized to 1.*(argv + i)
instead of argv[i]
- it evaluates to the same thing, but is more verbose.