-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_isnumber.c
46 lines (42 loc) · 1.41 KB
/
ft_isnumber.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isnumber.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dbrandao <dbrandao@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/27 17:43:33 by dbrandao #+# #+# */
/* Updated: 2022/10/27 17:45:08 by dbrandao ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static void pass_spaces(char **str)
{
while (ft_isspace(**str))
(*str)++;
}
static int is_number(char *str)
{
if (!str)
return (0);
if (ft_issign(*str))
str++;
if (!*str)
return (0);
while (ft_isdigit(*str))
str++;
if (!ft_isspace(*str) && *str != '\0')
return (0);
return (1);
}
char *ft_isnumber(char *str)
{
if (!str || !*str)
return (NULL);
pass_spaces(&str);
if (!ft_isdigit(*str) && !ft_issign(*str))
return (NULL);
if (is_number(str))
return (str);
return (NULL);
}