Skip to content

Commit 8322be7

Browse files
author
Shell-thon
committed
update
1 parent 957df79 commit 8322be7

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "main.h"
2+
/**
3+
* _atoi - Convert string to integer.
4+
* @s: Pointer to a character string.
5+
*
6+
* Return: void.
7+
*/
8+
9+
int _atoi(char *s)
10+
{
11+
int sign;
12+
unsigned int num;
13+
char *temp;
14+
15+
temp = s;
16+
num = 0;
17+
sign = 1;
18+
while (*temp != '\0' && (*temp < '0' || *temp > '9'))
19+
{
20+
if (*temp == '-')
21+
sign *= -1;
22+
temp++;
23+
}
24+
if (*temp != '\0')
25+
{
26+
do {
27+
num = num * 10 + (*temp - '0');
28+
temp++;
29+
} while (*temp >= '0' && *temp <= '0');
30+
}
31+
return (num * sign);
32+
}

0 commit comments

Comments
 (0)