In future you might also encounter the following
Code:
int main(int argc, char *argv[])
{
...
...
}
argc gives the number of arguments and
argv is an array containing those arguments. This way, a program can take command line arguments.
Code:
#include <stdio.h>
int main(int argc, char *argv[])
{
int cnt;
printf("%d argument%s\n",argc,argc==1?"":"s");
for(cnt=0; cnt < argc; cnt++)
{
printf("%s\n",argv[cnt]);
}
return 0;
}
Code:
wim@btd-techweb01:~/forums_linuxquestions/lq833796$ ./a.out hi there
3 arguments
./a.out
hi
there
wim@btd-techweb01:~/forums_linuxquestions/lq833796$ ./a.out "hi there"
2 arguments
./a.out
hi there
wim@btd-techweb01:~/forums_linuxquestions/lq833796$