C program using command line argument.

 

01 #include <stdio.h>
02
03 int main( int argc, char *argv[] )
04 {
05 printf("Program name %sn", argv[0]);
06
07 if( argc == 2 )
08 {
09 printf("The argument supplied is %sn", argv[1]);
10 }
11 else if( argc > 2 )
12 {
13 printf("Too many arguments supplied.n");
14 }
15 else
16 {
17 printf("One argument expected.n");
18 }
19 return 0;
20 }
 
 OUTPUT :

Program name CMD_Demo.exe

The argument supplied is Hello

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.