2021-04-27 18:33:31 +02:00
|
|
|
#include <ctype.h>
|
2022-04-15 11:00:55 +02:00
|
|
|
#include <stdlib.h>
|
2021-04-27 18:33:31 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
** atoi(s) - convert s to integer.
|
|
|
|
*/
|
2022-04-15 11:00:55 +02:00
|
|
|
int atoi(const char* s)
|
2021-04-27 18:33:31 +02:00
|
|
|
{
|
|
|
|
int sign, n;
|
2022-04-15 11:00:55 +02:00
|
|
|
while (isspace(*s))
|
|
|
|
++s;
|
2021-04-27 18:33:31 +02:00
|
|
|
sign = 1;
|
2022-04-15 11:00:55 +02:00
|
|
|
|
|
|
|
switch (*s) {
|
|
|
|
case '-':
|
|
|
|
sign = -1;
|
|
|
|
case '+':
|
|
|
|
++s;
|
2021-04-27 18:33:31 +02:00
|
|
|
}
|
2022-04-15 11:00:55 +02:00
|
|
|
|
2021-04-27 18:33:31 +02:00
|
|
|
n = 0;
|
2022-04-15 11:00:55 +02:00
|
|
|
while (isdigit(*s))
|
|
|
|
n = 10 * n + *s++ - '0';
|
2021-04-27 18:33:31 +02:00
|
|
|
return (sign * n);
|
|
|
|
}
|