CodesJava

Easy learning with example program codes

C Command Line Arguments


Command line arguments are passed inside the main function of a C program also called as command line of the C program, hence the name, command line arguments.

Syntax:

data_type main(int argc, char *argv[] )

  • Argc: This is a mandatory parameter that counts the number of arguments.
  • Argv[]: This is also a mandatory parameter that contains all the arguments.

Example:

#include <stdio.h>  
void main(int argc, char *argv[] )  
{  
printf("File name: %s\n", argv[0]);  
 
if(argc < 2)
{  
      printf("No argument passed.\n");  
   }  
else
{  
      printf("Argument 1: %s\n", argv[1]);  
   }  
}

Output

File name: C_program
Argument 1: welcome
Posted in C   
Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki