Argc argv playground added
This commit is contained in:
parent
120090c2bf
commit
28e9800830
1 changed files with 26 additions and 0 deletions
26
c_modern_approach/Strings/argc_argv.c
Normal file
26
c_modern_approach/Strings/argc_argv.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
int main(int argc, char *argv[]) {
|
||||
// Reading CLI arguments
|
||||
char **p;
|
||||
// Iterating from 1 due to the app name at 0 index
|
||||
for (p = &argv[1]; *p != NULL; p++) {
|
||||
printf("%s\n", *p);
|
||||
}
|
||||
printf("-----\n");
|
||||
// Another way
|
||||
for (int n = 1; n < argc; n++) {
|
||||
char *argument = argv[n];
|
||||
// Option 1 (Idiom 1 of finding end of string)
|
||||
/* printf("%c", *argument); */
|
||||
/* while (*argument++) { */
|
||||
/* printf("%c", *argument); */
|
||||
/* } */
|
||||
// Option 2 (Idiom 2 of finding end of string)
|
||||
while (*argument) {
|
||||
printf("%c", *argument);
|
||||
argument++;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue