// This program demonstrates the use of command line arguments // We are used to seeing int main(void), where no inputs are given to our // main function when it first runs. What if we were to change that to allow // the main function to accept arguments on running? // Sasha Vassar Week 5, Lecture 10 #include int main (int argc, char *argv[]) { printf("There are %d command line arguments in this program\n", argc); //argv[0] is always the program name printf("The program name is located in argv[0] and is %s\n", argv[0]); //./argv_demo Alvin //argv[0] = ./argv_demo //argv[1] = "Alvin" //argv[1][0] = 'A' //argv[1][1] = 'l' printf("argv[3][0] = %c\n", argv[3][0]); //Let's now print out all the command line arguments given int i = 1; while (i < argc) { printf("The command line argument at index %d (argv[%d]) is %s\n", i, i, argv[i]); i++; } return 0; }