argc - argument counter

Stores how many arguments system shell provided in the command line to run that application thus holding the count of argv

argv - argument vector

Argument vector is a pointer to a pointer which contains a list of strings. It stores the list of the individual argument entries. This list or array contains a series of pointers starting from 0 which is program name/path the arguments placed at one after another. Argc or argument count is the first argument which holds the total number of elements in this argv.

Source code

#include <stdio.h>
int main (int argc, char *argv[])
  int count;
  printf ("Total %d user arguments\n", argc - 1);
  printf ("Program arguments:\n");
  for (count = 0; count <argc; count++)
10    {
11      printf ("argv [%d] = %s\n", count, argv [count]);
12    }
13    return 0;
14  }


$ gcc  argc_argv.c -o argc_argv
$ ./argc_argv arg1 arg2 arg3
Total 3 user arguments
Program arguments:
argv [0] = ./env_argv
argv [1] = arg1
argv [2] = arg2
argv [3] = arg3

You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

Quick Sort, Heap Sort, Merge sort, Radix Sort, argc and argv, C startup routine, argv environ getenv, system(), atexit,

# C Programming Language (Prentice Hall Software)
# Let Us C Paperback - 2006 by Yashavant Kanetkar
# Understanding and Using C Pointers Core techniques for memory management
# Data Structures Using C and C++ Paperback - 1998
# Data Structures In C Paperback - August 11, 2008 by Noel Kalicharan