init
This commit is contained in:
BIN
C/c04v2/ex03/a.out
Executable file
BIN
C/c04v2/ex03/a.out
Executable file
Binary file not shown.
65
C/c04v2/ex03/ft_atoi.c
Normal file
65
C/c04v2/ex03/ft_atoi.c
Normal file
@ -0,0 +1,65 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/19 10:08:23 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/25 18:42:46 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_whitespaces(char *str)
|
||||
{
|
||||
char *space;
|
||||
int j;
|
||||
int i;
|
||||
|
||||
space = "\n\r\v\t\n ";
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (space[i] != 0)
|
||||
{
|
||||
while (str[j] == space[i])
|
||||
{
|
||||
if (str[j] == 0)
|
||||
return (j);
|
||||
i = 0;
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (j);
|
||||
}
|
||||
|
||||
int ft_atoi(char *str)
|
||||
{
|
||||
int i;
|
||||
int sign;
|
||||
int nbr;
|
||||
|
||||
sign = 1;
|
||||
nbr = 0;
|
||||
i = ft_whitespaces(str);
|
||||
while (str[i] == '+' || str[i] == '-')
|
||||
{
|
||||
if (str[i] == '-')
|
||||
sign = sign * -1;
|
||||
i++;
|
||||
}
|
||||
while (str[i] >= '0' && str[i] <= '9')
|
||||
{
|
||||
nbr = nbr * 10 + str[i] - '0';
|
||||
i++;
|
||||
}
|
||||
return (nbr * sign);
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main ()
|
||||
{
|
||||
printf("%d", ft_atoi(" +--+-++--00000132563hhi2167"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user