/* File CExamples/mainarg.c */ #include #include /* for strlen */ #include /* for isprint */ int main(int argc, char *argv[]) /* This program manipulates the arguments to main for purpose of demonstrating the use of characters, strings, and arrays of strings, pointers and their integer values in C */ {int i; char *cptr; char *lastarg_firstcptr; /* points to first character of last argument */ char *lastarg_termincptr; /* points to null char terminating last argument */ printf("argc == %2d\n", argc); /* print the location of the argument string in hexadecimal, and then print the string */ for (i=0; i < argc; i++) printf("Address of argv[%1d] == %p, string value == \"%s\"\n", i, argv[i], argv[i] ); printf("\n"); /* Now print each character in the range of the first character of the first argument to the null character terminating the last argument */ printf("argv == %p\n", argv); lastarg_firstcptr = argv[argc-1]; lastarg_termincptr = lastarg_firstcptr + strlen(lastarg_firstcptr); for(cptr = *argv; cptr <= lastarg_termincptr; cptr++) if(isprint((int)*cptr)) printf("Address == %p, character value == '%c'\n", cptr, *cptr); else printf("Address == %p, character value == '\\%03o'\n", cptr, *cptr); return 0; }