Wednesday, 10 September 2014

Command line argument in C Language Program with example

Command line argument in C: An example C program is available here. Given source code is based on command line operations by passing arguments with the advantage of arrays. Sample code is also given below for your reference.

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
//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]);
        puts("No command line argu entered.");
    return 0;

No comments:

Post a comment

Note: only a member of this blog may post a comment.