Commit | Line | Data |
---|---|---|
1968fc94 LM |
1 | #include "atoi.h" |
2 | ||
3 | int atoi (char *str) | |
4 | { | |
5 | int i = 0; | |
6 | int s = 1; | |
7 | ||
8 | if (*str == '-') { | |
9 | s = 0; | |
b449884c | 10 | str++; |
1968fc94 LM |
11 | } |
12 | ||
13 | while (*str != 0) { | |
14 | if ((*str <'0') || (*str > '9')) { | |
15 | return 0; | |
16 | } | |
17 | i = i * 10 + (int)(*(str++) - '0'); | |
18 | } | |
19 | ||
20 | return (s) ? i : -i; | |
21 | } | |
22 | ||
b449884c | 23 | /* vim: set ts=4 sw=4 et: */ |