Executable instructions that perform operating system tasks are called commands. These commands are issued from the operating system prompt.
The parameters associated with the command are as follows:
argc - Argument count.
argv - Argument vector.
argc - It holds the total number of arguments passed from the command prompt.
argv - It is a pointer to a character string array containing the names of the arguments.
For example:
c: |> sample. Exe hello how are you arguments
Here,
argc = 5
argv[0] = sample.exe
argv[1] = hello
argv [2] = how
argv[3] = are
argv[4] = you
Here is the C program for command line arguments:
#include<stdio.h> main ( int argc, char *argv[ ]){ int i; clrscr( ); printf (" no. of arguments at command p = %d", argc); printf (" arguments given at prompt are </p><p>"); for ( i = 1; i <argc; i++) printf ("%s</p><p> ", argv[i]); getch( ); }
Using command line arguments Run the C program:
Compile the program
Run the program
Go to the command prompt and Enter as shown below.
c:|> sample.exe hello how are you. No. of arguments given at prompt is = 5 Arguments given at command prompt are: hello How Are You
The above is the detailed content of In C language, command line parameters refer to parameters passed to the program through the command line when the program is running.. For more information, please follow other related articles on the PHP Chinese website!