Command-Line Arguments in C — a practical guide to C argc argv with clear examples you can reuse in real projects.
C Programming Tutorial Series (84/102). Prefer one article? Read the complete C programming tutorial.
Short description
argv[0] is the program name; validate argc before using argv[i].
argc/argv
int main(int argc, char *argv[]) {
if (argc < 2) {
printf("Usage: %s <file>n", argv[0]);
return 1;
}
printf("File: %sn", argv[1]);
return 0;
}