CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
Module 04 Command Line arguments in C
1. See through C
Module 4
Command Line Arguments
Tushar B Kute
http://tusharkute.com
2. The main( ) function
●
So far, we have been defining the main()
function to receive no arguments.
●
Actually, the main( ) function can receive
two arguments.
●
To do that, the main( ) function should
be defined as below.
●
This is how arguments can be passed in
at the command line.
http://www.tusharkute.com 2
int main(int argc, char *argv[ ]) { … }
3. ●
From the command prompt, we can start
running a program by typing its name and
pressing ENTER.
●
To pass arguments, we type in the
program’s name followed by some
arguments, then press ENTER.
●
Below is an example from the Unix
command prompt.
Command Line Arguments
% ./myprog
% ./myprog 5 23
4. argc and argv
●
When the program is called from the
command line with arguments, argc will
contain the number of arguments.
●
When the user types in arguments, the user
separates each argument with a space.
●
argv is an array of character strings.
●
argv[1] is the character string containing the
first argument, argv[2] the second, etc.
●
Note: argv[0] contains the character string
that is the name of the executable/binary.
5. Example
int main(int argc, char *argv[ ])
{
int i;
for (i = 1; i < argc; i++)
printf("%s ", argv[i]);
printf("n");
return 0;
}