Programming Example
Command Line Arguments Basic Program
Program to print all value of command-line argument once we get the value from the command line we can use them to solve our problem
// Program to print all value of
// command line argument
// once we get the value from command
// line we can use them to solve our problem
#include <stdio.h>
int main(int argc, char *argv[])
{
int a,b;
int i;
if(argc<2)
{
printf("please use \"prg_name value1 value2 … \"\n");
return -1;
}
for(i=1; i<argc; i++)
{
printf("arg[%2d]: %d\n",i,atoi(argv[i]));
}
return 0;
}
11 22 33
First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.
After understanding this example, try to rewrite the same program without looking at the code. Then change some values or logic and run it again. This helps improve confidence and keeps learners engaged on the page for longer.