This commit is contained in:
Tanguy MAZE 2018-04-05 14:29:46 +02:00
parent 9e7312327a
commit c4402c4b2d
3 changed files with 44 additions and 3 deletions

View File

@ -6,7 +6,7 @@
# By: tmaze <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2018/04/04 10:51:59 by tmaze #+# #+# #
# Updated: 2018/04/05 13:16:24 by tmaze ### ########.fr #
# Updated: 2018/04/05 14:13:58 by tmaze ### ########.fr #
# #
#******************************************************************************#
@ -29,6 +29,7 @@ SRCS = \
ft_strnstr.c \
ft_strcmp.c \
ft_strncmp.c \
ft_atoi.c \
ft_isalpha.c \
ft_isdigit.c \
ft_isalnum.c \

40
ft_atoi.c Normal file
View File

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/05 13:50:22 by tmaze #+# #+# */
/* Updated: 2018/04/05 14:24:13 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int nbnum;
int mult;
int ret;
nbnum = 0;
while (str[nbnum] == ' ' || str[nbnum] == '\t' || str[nbnum] == '\n'\
|| str[nbnum] == '\v' || str[nbnum] == '\f' || str[nbnum] == '\r')
nbnum++;
if (str[nbnum] == '+' || str[nbnum] == '-')
nbnum++;
while (str[nbnum] != '\0' && str[nbnum] >= '0' && str[nbnum] <= '9')
nbnum++;
nbnum--;
ret = 0;
mult = 1;
while (nbnum >= 0 && (str[nbnum] >= '0' && str[nbnum] <= '9'))
{
ret += (str[nbnum--] - '0') * mult;
mult *= 10;
}
if (nbnum >= 0 && str[nbnum] == '-')
ret *= -1;
return (ret);
}

View File

@ -6,7 +6,7 @@
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/04 10:40:01 by tmaze #+# #+# */
/* Updated: 2018/04/05 13:11:35 by tmaze ### ########.fr */
/* Updated: 2018/04/05 13:51:17 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
@ -40,7 +40,7 @@ char *ft_strstr(const char *haystack, const char *needle);
char *ft_strnstr(const char *haystack, const char *needle, size_t len);
int ft_strcmp(const char *s1, const char *s2);
int ft_strncmp(const char *s1, const char *s2, size_t n);
int ft_atoi(const char *nptr);
int ft_atoi(const char *str);
int ft_isalpha(int c);
int ft_isdigit(int c);
int ft_isalnum(int c);