what is difference between argc and argv
how to use it
what is difference between argc and argv
how to use it
EmbLogic Research & Competency Development Labs
Phone: +91 9818467776, 8527567776, 9650467776
Email: info@emblogic.com
Copyright © EmbLogic Embedded Technologies Pvt. Ltd.
Actually argc and argv are command line parameters. argc means number of commands entered via command line and the entered command is stored as a string in argv which is a character of pointers.
lets take an example
when we want to execute a program we type the command as
root@localhost~]#./a.out
This command is treated as 1 by argc and the ./a.out is stored in argv[0].
To get the result you can write a simple program as
int main(int argc,char *argv[])
{
printf(” Command number: %d\n”,argc);
printf(” Command name: %s\n”,argv[0]);
return 0;
}
Subsequently the number of commands entered are stored in argv for example
root@localhost~]#./a.out hello world
argv[0] – ./a.out
argv[1] – hello
argv[2] – world
and number of commands are three