Sunday, 21 January 2018

Command Line arguments


Command Line arguments

Command Line arguments
Definition: It is a parameter supplied to a program when the program is invoked.These are the
arguments passed to the main at command prompt.

Explanation:

main() function in 'c' takes two arguments called argc,argv.The information contained in the command arguments ,when main is called up by the stream. argc: The variable argc is an argument counter that counts the number of arguments on the command line.

argv:  The argv is an argument vector and represents an array of character pointers that point to the command line arguments.The size of array will be equal to argc.



   Ex: c:\> program x-file y-file

      here argc=3.
           argv[0]= program.
           argv[1]=x-file.
   argv[2]=y-file.
i.e.., here argv[0] contains the base address of string
"program"  argv[1]  contains the base address of string
"x-file"   argv[2]  contains the base address of string
"y-file"
  Therefore arguments that we pass to main at command prompt are command line arguments.

Advantages of command line arguments:

1.There is no need to recompile the program everytime we want to use this utillity.It can be executed at command prompt.

2.Once executable file is created nobody with malicious intention can tamper with your source code program.

3.We can pass source file name and target file name to main(), and utillise them in  main().

Related Posts:

  • String Handling Functions In CString Handling Functions In CWith every C compiler a large set of useful string handling library functions are provided. The following figure illustrates the more commonly used functions along with theirpurpose.1.strlen: Fin… Read More
  • Programs In String Handling FunctionsPrograms In String Handling Functions1.Is the folowing program correct or not?   yes/nomain(){  char *str1 = "United";  char * str2 = "Front";  char  *str3;  str3 = strcat(str1, str2); … Read More
  • Limitations of array Pointers to stringsLimitations of array Pointers to stringsWhen we are using a two-dimensional array of characters we are at liberty to either initialize the strings where we are declaring the array, or receive the stringsusing scanf() function… Read More
  • Basic PointersBasic PointersPointer Definition: Pointer is a variable which contains the address of another variable.Reasons for using pointer:1.A pointer enables us to access a variable that isdefined outside the function.2.Pointers are m… Read More
  • Array Of Pointers To StringsArray Of Pointers To StringsAs we know , a pointer variable always contains an address. Therefore , if we construct an array of pointers it would contain a number of addresses.Let us see how the names in the earlier example c… Read More

0 comments:

Post a Comment