C Program to Demonstrate getting the parameters from the command line.

C Program to getting the parameters from the command line. To pass the arguments from command line, in main function we have to declare two arguments . First one is number of arguments passed to the program and other one is pointer variable which gives the list of arguments passed. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/



#include <stdio.h>

main(int argc, char *argv[]) {
int count;

/* Main takes two variables 'argc' is the number of parms on the
* command line and 'argv' is a pointer to each of the parameters.
*
* int argc -- integer number called 'argc'
* char *argv[] -- Character pointer array!
*/

printf("%i parameters entered on the command line.n", argc);

/*
* progname argc = 1
* progname parm1 parm2 argc = 3
*/

/*
* We take 1 from argc because
* the argv array starts at zero
* an ends at argc -1
*/

for (count = 0; count <= argc - 1; count++) {
/* printf expects a pointer
* to the text
*/

printf("parm %d is %sn", count, argv[count]);
}
}
Read more Similar C Programs
C Strings

Simple C Programs

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

Leave a Reply