Advertisement
pasholnahuy

3

Nov 20th, 2023
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <errno.h>
  2. #include <stdint.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. int main(int argc, char **argv) {
  7. for (int i = 1; i < argc; ++i) {
  8. char *num_end;
  9. errno = 0;
  10. long num = strtol(argv[i], &num_end, 10);
  11. if (errno == ERANGE) {
  12. printf("%d\n", -1);
  13. continue;
  14. }
  15. if (*num_end == 0 && num_end != argv[i]) {
  16. if ((int8_t)num == num) {
  17. printf("%d\n", 1);
  18. } else if ((int16_t)num == num) {
  19. printf("%d\n", 2);
  20. } else if ((int32_t)num == num) {
  21. printf("%d\n", 4);
  22. } else {
  23. printf("%d\n", -1);
  24. }
  25. } else {
  26. printf("%d\n", -1);
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement