#include #include int ch; int nextCh(void) { ch = getchar(); return ch; } bool isSpace(int ch) { return ch == ' '; } bool isDecDigit(int ch) { return ch >= '0' && ch <= '9'; } bool isOctDigit(int ch) { return ch >= '0' && ch <= '7'; } bool getUint(unsigned long long *res) { unsigned long long val = 0; // state S while (ch == 0 || ch == ' ') { nextCh(); } if (ch == '0') { nextCh(); if (ch == 'x') { nextCh(); // state HT, H /* * TODO: Begin of your Code */ return false; /* * TODO: End of your Code */ } // state OT or O while (isOctDigit(ch)) { ch -= '0'; val = val * 8 + ch; nextCh(); } *res = val; return true; } else if (isDecDigit(ch)) { // state D while (isDecDigit(ch)) { ch -= '0'; val = val * 10 + ch; nextCh(); } *res = val; return true; } else { return false; } } int main() { unsigned long long val = 0; printf("Type some unsigned integer in decimal, octal or hex: "); if (getUint(&val)) { printf("Integer in decimal representation: %llu\n", val); } else { printf("That is not an unsigned integer in decimal!\n"); } }