The books i have already read :-

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

Dani AI

Generated

— a short, practical route is usually better than diving back into dense standards text. ’s one-line demo is a fine quickstart, but the usual next steps are learning a small option-parsing library and robust string-to-number conversion. Two compact, approachable references that hit those needs are Steve Oualline’s Practical C Programming (hands-on examples and a chapter on command-line use) and O’Reilly’s C Pocket Reference (fast lookup for the functions you’ll use). (oreilly.com)

When choosing a short book, focus on three concrete skills: option parsing (getopt / getopt_long), safe numeric parsing and error checking (strtol / strtoll with endptr and errno), and handling shell quoting / remaining positional arguments. The GNU C Library manual gives clear, canonical guidance on option parsing and long options, and on safe parsing of integers. Reading those two manual sections alongside a short book will cover real-world needs quickly. (gnu.org)

Two tiny patterns to copy into real code:

/* getopt skeleton */
int opt;
while ((opt = getopt(argc, argv, "ho:n:")) != -1) {
  switch (opt) {
  case 'h': /* print help */ break;
  case 'o': output = optarg; break;
  case 'n': /* parse below */ break;
  default: /* usage */ return 1;
  }
}
/* remaining args start at argv[optind] */
/* safe integer parse */
errno = 0;
char *end;
long v = strtol(optarg, &end, 10);
if (end == optarg) { /* no digits found */ }
else if (errno == ERANGE) { /* out of range */ }
else { /* v is valid */ }

For a compact learning path: skim the pocket reference as you code, work through the short, project-based chapters in Oualline to see real examples, and use the GNU manual for getopt/strtol examples and details. (oreilly.com)

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:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.