Command Line Argument
1. Command line argument is a way of supplying parameter to the program whenever it is invoked.
In command line argument when user call main method it is called by two arguments.The first is the number of command-line argument.
The second is a pointer to an array of character string that contain the argument, one per string.
which echoes its command-line arguments on a single line, separated by blank space.
i.e
echo hello, family
prints the output
hello, family
Source Code for command lline argument
#include
int main( int argument, char *argument1[] )
{
if( argument == 2)
{
printf("The arguments you have supplied is %s\n", argument1[1]);
}
else if( argument> 2 )
{
printf("many arguments supplied.\n");
}
else
{
printf("Atleast one argument expected here.\n");
}
}
output:-
when you compile code like this:
./out shristi
The argument you have supplied is shristi
./out shristi nawani
Many arguments supplied.
./out
Atleast One argument expected here.
0 Comment(s)