/ Published in: C
Expand |
Embed | Plain Text
int _asc2int(const char* s) { int i = 0; // return 0 on any other character while (*s != 0) { if (*s >= '0' && *s <= '9') { i = i * 10 + (*s - '0'); s++; } else return 0; } return i; } int asc2int(const char* s) { // leading '+' and '-' allowed int sign = 1; if (*s == '+') s++; if (*s == '-') { sign = -1; s++; } return _asc2int(s) * sign; } int main() { char s[] = "-975310"; return 0; }
You need to login to post a comment.
