40 likes | 55 Views
CSc 352 Command Line Processing. Saumya Debray Dept. of Computer Science The University of Arizona, Tucson debray@cs.arizona.edu. Accessing command line arguments. Command-line arguments to a program are given to the program as an array of (pointers to) strings char *argv[]
E N D
CSc 352Command Line Processing Saumya Debray Dept. of Computer Science The University of Arizona, Tucson debray@cs.arizona.edu
Accessing command line arguments • Command-line arguments to a program are given to the program as an array of (pointers to) strings char *argv[] • No. of arguments (= size of this array) provided separately int argc • Accessed within the program as int main(int argc, char *argv[]) program name first argument last argument
Example 1 argv[0] is always the name of the executable argv[01] … argv[(argc-1)] are the command line arguments, in order
Example 2 array pointer