github to gitea
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
Reference in New Issue
Block a user