ASP ScriptingJava ScriptingCGI ScriptingHTMLJavaLanguage CERP Education Links

LANGUAGE C

Command Line Arguments

     A command-line argument is the information that follows the program name on the command line of the operating system. Sometimes it is useful to pass information into main() function with command-line arguments.

     There are two special built-in arguments argv and argc, that are used to receive command-line arguments. The argc parameter holds the number of arguments on the command-line and it must be at least one integer because the name of the program qualifies as the first argument. The argv parameter is a pointer to an array of character pointers. 

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
main ( int argc, char *argv[] )
{
int disp, count;
if ( argc <2)
{
printf ("\n The Length of count has to be Entered");
exit(1);
}
if (argc == 3 && ! strcmp (argv[2],"display"))
disp=1;
else
disp=0;
count=atoi(argv[1]);
for ( count = atoi ( argv[1] ); count; --count)
{
if (disp)
{
printf("%5d",count);
}
}
putchar(7);
printf ( "Completed...");
}

 


Your Ad Here
Not All Of Your Subscribers Use RSS - AWeber Email Marketing
Your Ad Here