/* * Program to echo command-line arguments, one per line, and do a little * processing of each. */ #include #include #include /* 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 (%zd characters not read)\n", strlen(endptr)); } } return EXIT_SUCCESS; }