Argc argv playground added

This commit is contained in:
pro100ton 2024-12-22 21:14:48 +03:00
parent 120090c2bf
commit 28e9800830

View 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");
}
}