How to define command line arguments

The main functions can have in it arguments passed which are called as command line arguments. The command line arguments are two in number which are namely:



Argument count denoted by argc and

Argument vector denoted by argv



The argc is an integer variable which denotes the number of parameters passed and argv is pointer to array of character strings.


The syntax is as follows:



main( int argc , char * argv[ ])

{

.......

.....

}



It can also be return as



main(argc,argv)

int argc;

char * argv[];

{

........

.......

}



After the program is executed the first argument entered in prompt would be the name of the program which is to be executed followed by parameters. Sa y for example if the program name of execution is sample and say 3 values are to be passed namely a1,a2,a3 it is given as follows:



sample a1 a2 a3



So in this case argc have value as 3 which is the number of parameters passed and argv would have values as



argv[0]= sample

argv[1]=a1

argv[2]=a2

argv[3]=a3


Questions by GeekAdmin   answers by GeekAdmin

Showing Answers 1 - 3 of 3 Answers

sonal

  • Nov 24th, 2007
 

It should defined globally in C
main(int argc , char *argv[])
{

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions