Get input value from command line in C language program

Get input value from command line in C language program

The C language main function provides two parameters, which are used to provide relevant parameters when running the program.

argc indicates the number of parameters (including the program name itself)
Argv is an array of parameters.

For example:

hello.exe lautturi world
‮cruoS‬e:www.lautturi.com

argc => 3,
argv[0] => hello.exe
argv[1] => lautturi
argv[2] => world

/*
Example: Get input value from terminal in C language
*/

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char const *argv[])
{
    int rings;
    if(argc != 3) {
        printf("Usage: %s str1 str2\n",argv[0]);
        return 1;
    }

    printf("argv[0] %s\n", argv[0]);
    printf("argv[1] %s\n", argv[1]);
    printf("argv[2] %s\n", argv[2]);
    return 0;
}

example of output:

hello.exe lau-tturi world
argv[0] F:\Debug\hello.exe
argv[1] lau-tturi
argv[2] world
Created Time:2017-08-29 09:19:07  Author:lautturi