Thursday, 13 November 2014

Command Line Arguments in C

Command line arguments can be used to pass the input to the C program through command line.

Below screen shot shows how to execute the program with command line arguments using gcc in windows system.

We have sent one argument to the program – "sagar Salunke".

Program prints the length of the argument that we have passed.

#include <stdio.h>
#include <string.h>

int main (int c, char *arg[])

if (c < 2)
      printf("too less arguments");
      return -1;
 printf("Number of command line arguments - %d \n" , c);
 printf("Length of the argument is %d", strlen(arg[1]));

Sponsored Links

Popular Posts



Google+ Followers

Google+ Badge