Command Line Interface | Argumentation


Command Line Interface
Spread the love

In the following article we are discussed related to command line interface used in programming along with types of arguments passed in it. The process of argumentation means passing the arguments during main() function of every program.

Command Line arguments:

First we discuss about basic concepts related to command line argument.

 

What is mean by command prompt?

  • Every computer has operating system software, at the time of set up some by default applications are installed.
  • We can open it as:
    1. Click on start button of Windows at the bottom left.
    2. Then type the text “Command Prompt”.
    3. Right click on option Command Prompt and select option “Run as administrator”.
    4. The Command Prompt should appear.
  • Command prompt is a place where we type the commands of operating system.
  • It is the part of operating system like-DOS command prompt.
  • If we install any software then it has its own GUI means Graphical User Interface.
  • The GUI has its own mouse input, you have to remember them to type and run the commands on that.
  • Beginner programmers are preferring to use it. while experienced programmers use Command Prompt more because of the facilities it has.

 

Let us consider an example to complete understand the concept.

  • You know the C programming Language which is the base of all programming language.
  • In C programming main function is the important and necessary part when we write the C program because main() is entry point of every function as well as from main() program execution starts.
  • From main() we call library as well as user defined functions and while doing this we send the arguments to those functions.
  • If so, then
    1. Can we pass the arguments to the main function as well?
    2. From where we send arguments to main function?
    3. Which are the types of arguments are they?
    4. What is the use of arguments passed to main function?
    5. In which situations to send arguments to main function?
  • The study of all these questions means Command Line Arguments.
  • At first when we write a C program, we save source code (.C file) in a folder.
  • Whenever we compile we found that object file (.obj) is created.
  • As well as after running the program, the executable file (.exe) is obtained.
  • And finally we run the executable file. So along with source code file, the object files and executable files are also stored on the machine.

 

Types of arguments:

  • We write main() in a program which takes two arguments.
  • One is integer and other is array of character pointers or array of strings.

Syntax:

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

Or

int main(int argc, char **argv);

Both statements have the same meaning.

For better understanding see the following program:

#include<stdio.h>
#include<conio.h>
int main(int n, char *ar[ ])
{
int i;
clrscr();
printf(“Arguments sent to main function\n”);
for(i = 0; i< n; i++)
{
printf(“%s “, ar[ i ]);
}
getch();
}

Save the program by name sample.c. Then compile it which makes sample.obj file.
Then go to the command prompt from the DOS shell sub-menu of the menu.

And we are going to run the executable file on the command prompt.
When we are using Turbo C, go to the directory where the executable is saved and you will see c:\> in front of the command prompt.

 

 

 

Related Articles: 

  1. Basic Accounting Concepts Part 1 

Some More: DBMS/ WT/ DMDW 

 


Spread the love