-1

The books i have already read :-

1. C ANSII Edition ( Cant understand their language )
2. C tutor
3. Pointers and memory ( Stanford )

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Narue
0

Simple and Brief Command Line Tutorial
by Narue

Command line arguments are sent to a C program through two parameters in main. The first parameter specifies the number of command line arguments. The second parameter is an array of strings listing each command line argument:

#include <stdio.h>

int main ( int argc, char *argv[] )
{
  int i;

  /* Print the command line arguments */
  for ( i = 0; i < argc; i++ )
    puts ( argv[i] );

  return 0;
}

The first command line argument (argv[0]) is the program name. Subsequent command line arguments are the actual arguments sent to the program:

$ myprog -a foo some_arg

argv[0] = "myprog"
argv[1] = "-a"
argv[2] = "foo"
argv[3] = "some_arg"

This concludes the lesson on command line arguments. Yes, it's really that simple. :icon_rolleyes:

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.