This is a C Program to print the program name and all its arguments.
This C Program Prints the Program Name and All its Arguments.
It prints the program name and its Arguments using command line argument as shown in the program below.
Here is source code of the C Program to Print the Program Name and All its Arguments. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/* * C Program to Print the Program Name and All its Arguments */ #include <stdio.h> void main(int argc, char *argv[]) /* command line Arguments */ { int i; for (i = 0;i < argc;i++) { printf("%s ", argv[i]); /* Printing the string */ } printf("\n"); }
In this C program, we are using command line arguments to print the program name by using argc and argv[] parameters. Using for loop the entered program name and its argument are printed by initializing the value of ‘i’ variable to zero. The loop will execute till the condition that value ‘i’ variable becomes less than the value of argc parameter. Print the program name entered in the command line argument.
$ cc arg9.c $ a.out this is c class by sanfoundry a.out this is c class by sanfoundry
Sanfoundry Global Education & Learning Series – 1000 C Programs.
Here’s the list of Best Books in C Programming, Data-Structures and Algorithms
- Check Computer Science Books
- Check C Books
- Apply for Computer Science Internship
- Watch Advanced C Programming Videos
- Practice BCA MCQs