Command Line Arguments
main() revisited
The main function actually takes two arguments - argc and *argv[]
argc is an integter with the value equal to the number of arguments passed
argv is a pointer array that points to each argument passed
Example:
int main(int argc, char * argv[]) { if (argc == 2) printf("%s was passed", argv[1]); return 0; }
*argv[0]
*argv[0] is a pointer to a string representing how the program was invoked
So, if no arguments were passed, argc would equal 1
For n arguments, argc = n + 1
TOC
|
<< Back
|
Next >>