0
What is command line arguments?
It will be helpful if explain with the example.. About command line arguments used in writing programs
5 Respuestas
+ 3
command line arguments are the arguments which are pass through command line. They are useful when you want to control your program from outside instead of hard coding.
+ 3
Command line arguments are passed to the main() method.
int main(int argc, char *argv[])
Here argc counts the number of arguments on the command line and argv[ ] is a pointer array which holds pointers of type char which points to the arguments passed to the program.
Example for Command Line Argument
#include <stdio.h>
#include <conio.h>
int main(int argc, char *argv[])
{
int i;
if( argc >= 2 )
{
printf("The arguments supplied are:\n");
for(i = 1; i < argc; i++)
{
printf("%s\t", argv[i]);
}
}
else
{
printf("argument list is empty.\n");
}
return 0;
}
Remember that argv[0] holds the name of the program and argv[1] points to the first command line argument and argv[n] gives the last argument. If no argument is supplied, argc will be 1.
+ 1
@Noa, you are right :-)
0
Thanks bro... M