Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
The integer, �argc� is the argument count. It is the number of arguments passed
into the program from the command line, including the name of the program.
�argv� is array of character pointers is the listing of all the arguments.
argv[0] is the name of the program, or an empty string if the name is not
available.
After that, every element number less than argc is a command line argument..
argv[argc] is a null pointer.
#include<stdio.h>
void main(int argc,char *argv[])
{
printf("Number of arguments : %d \n"argc);
}
#include<stdio.h>
void main(int argc,char *argv[])
{
int i ;
if(argc==1)
printf("No arguments passed\n");
else
{
printf("Arguments list : \n");
for(i=1 ; i<argc ; i++)
{
printf("%s \n", argv[i]);
}
}
#include<stdio.h>
void fun(int);
int main(int argc)
{
printf("%d\n", argc);
fun(argc);
return 0;
}
void fun(int i)
{
if(i!=4)
main(++i);
}
Note:
We can read command line arguments only in the form of String(char*) type.
We cannot process information directly.
We need to convert these arguments into primitive types using pre defined functions
dos.h header file contains pre defined functions to perform these conversions.
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char *argv[])
{
int a,b,c;
a=atoi(argv[1]);
b=atoi(argv[2]);
c=a+b;
printf("sum=%d\n",c);
return 0;
}