
COMMAND LINE ARGUMENT IN C
This C program is used to pass the arguments as the command statement. Declare the variables and pass the value by using a command format of statement.
//Header files
#include<stdio.h>
#include<conio.h>
//Global variables
int main(int ar, char *ar[])
{
int ct; //Program variables
clrscr(); //Function to clear previous output
printf("Program name: %s\n", ar[0]); //Display function
if(ar>1) //Conditional statement
{
for(ct=1; ct<ar; ct++) //Looping statement
printf("Argument %d: %s\n",ct,ar[ct]);
}
else
puts("No command line argu entered.");
getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
//Global variables
int main(int ar, char *ar[])
{
int ct; //Program variables
clrscr(); //Function to clear previous output
printf("Program name: %s\n", ar[0]); //Display function
if(ar>1) //Conditional statement
{
for(ct=1; ct<ar; ct++) //Looping statement
printf("Argument %d: %s\n",ct,ar[ct]);
}
else
puts("No command line argu entered.");
getch();
return 0;
}
No comments:
Post a comment
Note: only a member of this blog may post a comment.