/* C demo program. Print # of arguments & argument values */ /* CSE 374 lecture, 1/24/11, HP */ #include /* Again we have the argc and argv parameters In this program we actually access them and print them out. */ int main(int argc, char ** argv) { /* Variable declaration, note that C does not provide default values. If you forget to initialize a variable before using it, you may retrieve the junk that was sitting at that memory location. */ int k; /* Another example of printf, the integer value of argc will replace the %d before the string gets sent to printf. */ printf("argc = %d\n", argc); /* Typical for-loop, the 3 parts of ( Init ; Test ; Update ) Without beginning and ending { } will take just the next executable line as its body, even if it was not indented. */ for (k = 0; k < argc; k++) /* The string here has 2 formatting commands, %d and %s, that will be replaced by the values of k and argv[k] respectively before the string is sent to printf. argv[0] is the program itself, just like on the command line with scripts $0 is the script itself. */ printf("argv[%d] = %s\n", k, argv[k]); return 0; }