-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
print command line arguments on output
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* @file command-line-argument.c | ||
* @author kunal jain ([email protected]) | ||
* @brief Program to show use of command line arguments | ||
* @version 0.1 | ||
* @date 2022-03-31 | ||
* | ||
* @copyright Copyright (c) 2022 | ||
* | ||
*/ | ||
|
||
#include<stdio.h> | ||
|
||
int main(int argc, char** argv) { | ||
// argc -> total number of command line arguments | ||
// argv -> string array containing all the command line arguments | ||
// argv[0] -> name of the executable file | ||
|
||
// printf("Value of argc -> %d\n", argc); | ||
|
||
int i; | ||
|
||
// starting loop from 1 as 0th element in argv is name of | ||
// the executable file. We are concerned with strings present | ||
// after the first string. First string is just the name of | ||
// the exe file. | ||
|
||
// This loop prints whatever user inputs as command line argument. | ||
for (i = 1; i < argc; i++) { | ||
printf("%s", argv[i]); | ||
if ( i == argc - 1 ) { | ||
// it is last command line argument. | ||
printf("\n"); | ||
} | ||
else { | ||
// it is not last command line argument. | ||
printf(" "); | ||
} | ||
} | ||
return 0; | ||
} |