Command Line Arguments in C


Command Line Arguments in C

It is possible to values at command prompt using command line arguments in C. We need to specify the name of program followed by values we want to pass as arguments .

To implement command line arguments main() must have two parameters as: main ( int argc, char *argv[] )

  • argc specifies the number of arguments passed at command line.
  • *argv[] specifies the values passed as arguments at command line.
Program for command line arguments.
#include <stdio.h>
int main ( int argc, char *argv[] )
int counter;
printf(“Command line arguments”);

How to run:

  1. Name of program is supposed to be file.C
  2. Make its executable by compiling it.
  3. Go to Dos Shell from file menu.
  4. You need to type :file this is command line

The output of the program would be :

Command line arguments

d:\TCC\file.EXE  this

 Best Books of C

Lesson tags: Command Line Arguments in C, Test Your Knowledge in c, TIPS and tricks in c
Back to: C Programming Language