Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <errno.h>
- #include <stdint.h>
- #include <stdio.h>
- #include <stdlib.h>
- int main(int argc, char **argv) {
- for (int i = 1; i < argc; ++i) {
- char *num_end;
- errno = 0;
- long num = strtol(argv[i], &num_end, 10);
- if (errno == ERANGE) {
- printf("%d\n", -1);
- continue;
- }
- if (*num_end == 0 && num_end != argv[i]) {
- if ((int8_t)num == num) {
- printf("%d\n", 1);
- } else if ((int16_t)num == num) {
- printf("%d\n", 2);
- } else if ((int32_t)num == num) {
- printf("%d\n", 4);
- } else {
- printf("%d\n", -1);
- }
- } else {
- printf("%d\n", -1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement