1 #include <stdio.h> 2 #include <stdlib.h> 3 main()4int main() 5 { 6 char test[100] = {0}; 7 char *end = NULL; 8 read(0, test, 80); 9 10 if (strtol(test, &end, 0) == 0xaaaa) { 11 if (test[0] == '0' && test[1] != 'x') { 12 puts("base 8 worked"); 13 } 14 else if (test[0] == '+' && test[1] == '0' && test[2] != 'x') { 15 puts("base +8 worked"); 16 } 17 else if (test[0] == '0' && test[1] == 'x') { 18 puts("0x worked"); 19 } 20 else if (test[0] == '+' && test[1] == '0' && test[2] == 'x') { 21 puts("+0x worked"); 22 } 23 else if (test[0] == '+' && test[1] != '0') { 24 puts("base +10 worked"); 25 } 26 else { 27 puts("base 10 worked"); 28 } 29 } 30 else if (strtol(test, &end, 0) == -0xcdcd) { 31 if (test[0] == '-' && test[1] == '0' && test[2] != 'x') { 32 puts("base -8 worked"); 33 } 34 else if (test[0] == '-' && test[1] == '0' && test[2] == 'x') { 35 puts("-0x worked"); 36 } 37 else if (test[0] == '-' && test[1] != '0') { 38 puts("base -10 worked"); 39 } else { 40 puts("shouldn't happen"); 41 } 42 43 } else { 44 puts("Nope"); 45 } 46 return 0; 47 } 48 49