41 lines
1.2 KiB
C
41 lines
1.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_atoi.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/02/18 07:20:28 by lfirmin #+# #+# */
|
|
/* Updated: 2024/02/22 12:04:46 by lfirmin ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
#include <stdio.h>
|
|
|
|
int ft_atoi(char *c)
|
|
{
|
|
int n;
|
|
int s;
|
|
int nb;
|
|
|
|
n = 0;
|
|
s = 0;
|
|
nb = 0;
|
|
while (c[n] >= 9 && (c[n] <= 13 || c[n] == ' '))
|
|
n++ ;
|
|
while (c[n] == '-' || (c[n] == '+'))
|
|
{
|
|
if (c[n] == '-')
|
|
s++ ;
|
|
n++ ;
|
|
}
|
|
s = s % 2;
|
|
while (c[n] >= '0' && c[n] <= '9')
|
|
{
|
|
nb = (nb * 10) + (c[n] - 48);
|
|
n++ ;
|
|
}
|
|
if (s == 1)
|
|
nb = nb * -1;
|
|
return (nb);
|
|
}
|