-
Notifications
You must be signed in to change notification settings - Fork 0
/
is_valid_string.c
53 lines (47 loc) · 1.52 KB
/
is_valid_string.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
47
48
49
50
51
52
53
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* is_valid_string.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nkawaguc <nkawaguc@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/14 14:33:05 by nkawaguc #+# #+# */
/* Updated: 2024/10/20 14:38:52 by nkawaguc ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
static int ft_isspace(char c);
static int ft_isnull(char c);
int is_valid_string(const char *str)
{
int i;
long sign;
long num;
i = 0;
while (ft_isspace(str[i]))
i++;
sign = 1;
if (str[i] == '+' || str[i] == '-')
if (str[i++] == '-')
sign = -1;
if (!ft_isdigit(str[i]))
return (FALSE);
num = 0;
while (ft_isdigit(str[i]))
{
num = num * 10 + (str[i++] - '0') * sign;
if (num > INT_MAX || num < INT_MIN)
return (FALSE);
}
if (ft_isnull(str[i]))
return (TRUE);
return (FALSE);
}
static int ft_isspace(char c)
{
return ((9 <= c && c <= 13) || c == ' ');
}
static int ft_isnull(char c)
{
return (c == '\0');
}