MCPcopy Create free account
hub / github.com/IntegralPilot/wasm_os / atoi

Function atoi

stdlib/cpp/cstdlib.hpp:23–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21}
22
23int 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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected