Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <stdlib.h>
  4. #include <errno.h>
  5.  
  6. enum { BASE = 10 };
  7.  
  8. int main(int argc, char *argv[]) {
  9.     for (int i = 1; i < argc; ++i) {
  10.         errno = 0;
  11.         char* eptr;
  12.         int64_t n = strtol(argv[i], &eptr, BASE);
  13.         if (*eptr || errno) {
  14.             printf("-1\n");
  15.         } else {
  16.             int8_t n8 = n;
  17.             int16_t n16 = n;
  18.             int32_t n32 = n;
  19.             if (n8 == n) {
  20.                 printf("1\n");
  21.             } else if (n16 == n) {
  22.                 printf("2\n");
  23.             } else if (n32 == n) {
  24.                 printf("4\n");
  25.             }
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement