/* * Program to echo command-line arguments, one per line, and do a little * processing of each (to illustrate working with strings). */ #include #include /* returns length of string (i.e., same functionality as strlen() */ int mylength(char* s) { int count = 0; while (*s != '\0') { ++s; ++count; } return count; } /* main program */ int main(int argc, char* argv[]) { long n; char* endptr; for (int i = 0; i < argc; ++i) { printf("argv[%d] is '%s'\n", i, argv[i]); /* try to convert string to long int */ n = strtol(argv[i], &endptr, 10); if (*endptr == '\0') { printf("an integer (%ld)\n", n); } else { printf("not an integer (%d characters not read)\n", mylength(endptr)); } } return EXIT_SUCCESS; }