...
| Code Block | ||||
|---|---|---|---|---|
| ||||
int main(int argc, char *argv[]) {
if (argc < 2)
return EXIT_SUCCESS;
const char* const c_str = argv[1];
char *end;
int si;
errno = 0;
const long sl = strtol(c_str, &end, 10);
if (end == c_str) {
fprintf(stderr, "%s: not a decimal number\n", c_str);
}
else if ('\0' != *end) {
fprintf(stderr, "%s: extra characters at end of input: %s\n", c_str, end);
}
else if ((LONG_MIN == sl || LONG_MAX == sl) && ERANGE == errno) {
fprintf(stderr, "%s out of range of type long\n", c_str);
}
else if (sl > INT_MAX) {
fprintf(stderr, "%ld greater than INT_MAX\n", sl);
}
else if (sl < INT_MIN) {
fprintf(stderr, "%ld less than INT_MIN\n", sl);
}
else {
si = (int)sl;
/* processProcess si */
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}
|
...