bool isspace(int x)
{
if (x == ' ' || x == '\t' || x == '\n' || x == '\f' || x == '\b' || x == '\r') {
return true;
}
else {
return false;
}
}
bool isdigit(int x)
{
if(x<='9'&&x>='0') {
return true;
}
else {
return false;
}
}
int atoi(const char *nptr)
{
int current = 0;
int total = 0;
int sign = '+';
/* skip whitespace */
while (isspace((int)(unsigned char)*nptr)) {
++nptr;
}
current = (int)(unsigned char)*nptr++;
sign = current ; /* save sign indication */
if (current == '-' || current == '+'){
current = (int)(unsigned char)*nptr++; /* skip sign */
}
total = 0;
while (isdigit(current)) {
total = 10 * total + (current - '0'); /* accumulate digit */
current = (int)(unsigned char)*nptr++; /* get next char */
}
if (sign == '-') {
return -total;
}
return total; /* return result, negated if necessary
}