C Program to Print all Arguments passed using Command Line.
⦁ The command line arguments are handled using main( ) function arguments where argc refers to the number of arguments passed, and argv[ ] is a pointer array which points to each argument passed to the program.
⦁ The declaration for command line arguments is as follows:
int main(int argc, char *argv[ ])
⦁ argc - is the count of total command line arguments passed to executable on the time of execution.
⦁ argv - is the array of character string of each command line argument passed to executable on execution.
--------------------------------------------------------------------------------------------------------------------------
#include<stdio.h>
int main(int args, char *argv[ ])
{
int i=0;
for(i=0;i<args;i++)
printf("\n %s", argv[i]);
return 0;
}
--------------------------------------------------------------------------------------------------------------------------
Explanation
--------------------------------------------------------------------------------------------------------------------------
Steps to Run the Program
⦁ Save, Compile and Run the Program.
⦁ Open Command Prompt.
⦁ Move to the directory where program is saved.
⦁ Type the following command.
C:>TC>BIN>Example1 Monika Kushal
C:>TC>BIN>Example1.exe
Monika
Kushal
EmoticonEmoticon