mirror of
https://github.com/Ladebeze66/Piscine42.git
synced 2026-11-09 21:27:16 +01:00
Piscine42
This commit is contained in:
36
C04/ex03/ft_atoi.c
Executable file
36
C04/ex03/ft_atoi.c
Executable file
@@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/13 10:11:50 by fgras-ca #+# #+# */
|
||||
/* Updated: 2022/12/13 11:01:40 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_atoi(char *str)
|
||||
{
|
||||
int res;
|
||||
int sign;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
res = 0;
|
||||
sign = 1;
|
||||
while (str[i] == 32 || (str[i] >= 9 && str[i] <= 13))
|
||||
i++;
|
||||
while (str[i] == '-' || str[i] == '+')
|
||||
{
|
||||
if (str[i] == '-')
|
||||
sign *= (-1);
|
||||
i++;
|
||||
}
|
||||
while (str[i] >= '0' && str[i] <= '9')
|
||||
{
|
||||
res = res * 10 + str[i] - '0';
|
||||
i++;
|
||||
}
|
||||
return (res * sign);
|
||||
}
|
||||
Reference in New Issue
Block a user