#include #include int atoi(char string[]) { int i, sign_ext, res; for (i = 0; isspace(string[i]); ++i) ; sign_ext = string[i] == '-' ? -1 : 1; if (string[i] == '-') ++i; for (res = 0; isdigit(string[i]); ++i) { res = res * 10 + (string[i] - '0'); } return sign_ext * res; } int main() { printf("%d\n", atoi("123")); printf("%d\n", atoi("-123")); printf("%d\n", atoi("+123")); printf("%d\n", atoi("0123")); printf("%d\n", atoi("0123.1")); }