Skip to content

Commit

Permalink
print command line arguments on output
Browse files Browse the repository at this point in the history
  • Loading branch information
jainkhere committed Apr 3, 2022
1 parent e9152d3 commit ffd820d
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions command-line-argument.c
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;
}

0 comments on commit ffd820d

Please sign in to comment.