Introduction, Lecture 1

introduction to command line arguments

It is possible to pass some values from the command line to your C programs when they are executed. These values are called command line arguments.

We can’t use any input functions like scanf(), getch(), getchar().
The input to be provided should be read as command line arguments.

COMMAND LINE ARGUMENTS

int main(int argc, char *argv[])

COMMAND LINE ARGUMENTS IN C:

main() function of a C program accepts arguments from command
line or from other shell scripts by following commands.

They are argc and argv[]

where,

argc – Number of arguments in the command line
including program name (integer).
argv[] – This is carrying all the arguments including
program name (pointer array ).

Example of command line arguments

#include <stdio.h>

int main(int argc, char *argv[]) //command line arguments

{

printf(“\n Program name : %s \n”, argv[0]);

printf(“1st arg : %s \n”, argv[1]);

printf(“2nd arg : %s \n”, argv[2]);

return 0;

}

"<yoastmark

Properties of Command Line Arguments:

  1. They are passed to main() function.
  2. They are parameters/arguments supplied to the
    program when it is invoked.
  3. They are used to control program from outside
    instead of hard coding those values inside the code.
  4. argv[argc] is a NULL pointer.
  5. argv[0] holds the name of the program.
  6. argv[1] points to the first command line argument
    and argv[n] points last argument.

Here some easy problem that you can practice.


Regarding this course :

This course is an early bird release. More programs will be added in the coming days

If you are familiar with C programming, but you are not able to understand or write C program for a given problem, then this course helps in improving your coding skills.

In this course, 100 + C programs of different levels are explained clearly with pseudo code and tracing with sample inputs . After solving 100+ C programs, you will get a solid foundation in Coding.