GeekInterview.com
  I am new, Sign me up!
 
Home C
 

How to define command line arguments

 
Category: C
Comments (1)


The main functions can have arguments passed which are called as command line arguments. There are two command line arguments:


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 returned 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. Say 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



Read Next: How to develop compile and run a C program



 

 

Comments


gayandevi said:

  first compile
then go to dos shell in file menu
type the program name followed by arguments
July 6, 2008, 12:02 am

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact  

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape