The standard command-line arguments
In all of our C programs to date
we've seen the use of,
but not fully explained,
command-line arguments.
We've noticed that the main() function
receives command-line arguments from its calling environment
(usually the operating system):
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("program's name: %s\n", argv[0]);
for(int a=0 ; a < argc ; ++a) {
printf("%i: %s\n", a, argv[a] );
}
return 0;
}
|
|
|
We know:
- that argc provides the count of the number of arguments, and
- that all programs receive at least one argument (the program's name).
CITS2002 Systems Programming, Lecture 18, p1, 2nd October 2023.
|