Saturday, 26 March 2016

Command Line Arguments Program


Command line arguments are two types

1.   Argc
2.   Argv[]

you can pass these two arguments that are expected by the program. Argc parameter is the count of total command line arguments passed to executable on execution. Integer data type has to use for first parameter and for second parameter use character array. 

int main(int argc, char *argv[])
 
Argv parameter is the array of character string of each command line argument passed to executable on execution

If you are new to C programming, you should first understand how array works.


#include<stdio.h>
{
int main(int argc, int *argv[])
 int i;
 printf(“no arguments %d”,argc);
 for(i=0;i<argc;i++)
 {
    printf(“%s”,argv[i]);
 }
}
 
at the time of execution we have to give the input for command line arguments
 
$ ./a.out input1 input2

 

Out Put :

 
The argument is input1 input2
 
-----------------------------------------------------------------------------------------
More details about C interview questions and programs: http://learnclanguage4.blogspot.com/

No comments:

Post a Comment

Structure

Defination :-                           Structure is a user defined data type. struct keyword is used to define a structure. Structur...