Accessing command-line arguments. - C Function

C examples for Function:main function

Description

Accessing command-line arguments.

Demo Code

#include <stdio.h>

int main(int argc, char *argv[])
{
    int count;/*from  w w  w.j  a  v  a  2 s  . com*/

    printf("Program name: %s\n", argv[0]);

    if (argc > 1)
    {
        for (count = 1; count < argc; count++)
            printf("Argument %d: %s\n", count, argv[count]);
    }
    else
        puts("No command line arguments entered.");
    return 0;
}

Related Tutorials