| 21 | } |
| 22 | |
| 23 | int atoi(const char* str) { |
| 24 | // first check that there are not any non-digit characters |
| 25 | for (int i = 0; str[i] != '\0'; i++) { |
| 26 | if (str[i] < '0' || str[i] > '9') { |
| 27 | return 0; |
| 28 | } |
| 29 | } |
| 30 | int res = 0; |
| 31 | int sign = 1; |
| 32 | int i = 0; |
| 33 | |
| 34 | if (str[0] == '-') { |
| 35 | sign = -1; |
| 36 | i++; |
| 37 | } |
| 38 | |
| 39 | for (; str[i] != '\0'; ++i) { |
| 40 | res = res * 10 + str[i] - '0'; |
| 41 | } |
| 42 | |
| 43 | return sign * res; |
| 44 | } |
| 45 | |
| 46 | } // namespace std |
nothing calls this directly
no outgoing calls
no test coverage detected