-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_getnbr.c
executable file
·31 lines (28 loc) · 1.15 KB
/
ft_getnbr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_getnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: spariaud <spariaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/27 06:28:04 by spariaud #+# #+# */
/* Updated: 2014/11/27 06:46:35 by spariaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_getnbr(char *str)
{
int ret;
if (*str == '-')
return (-ft_getnbr(str + 1));
if (*str == '+')
return (ft_getnbr(str + 1));
ret = 0;
while (*str && *str >= '0' && *str <= '9')
{
ret *= 10;
ret = ret + *str - '0';
str++;
}
return (ret);
}