C Command Line Arguments


The arguments passed through the command line is called command line arguments. The main() function has handled command line arguments.


Syntax:

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

 

argc - the number of arguments.

argv[] -is a pointer array which points the total number of arguments.


Syntax:

#include <stdio.h>

void main( int argc, char *argv[] )  
{
	printf("Program name %s\n", argv[0]);
	if( argc == 2 ) {
		printf("The argument is %s\n", argv[1]);
   	}
   	else if( argc < 2) {
			printf("No argument pass through commandline\n");
		}
		else {
			printf("Too many argument pass through commandline\n");
		}
}



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.