-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils1.c
80 lines (73 loc) · 1.75 KB
/
utils1.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: crebelo- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/22 08:36:13 by crebelo- #+# #+# */
/* Updated: 2024/05/02 17:29:29 by crebelo- ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo.h"
int error_msg(char *msg, int n)
{
if (n != -1)
printf(msg, n);
else
printf("%s\n", msg);
return (1);
}
unsigned int ft_atoi(const char *nptr)
{
int i;
unsigned int res;
int sign;
i = 0;
res = 0;
sign = 1;
while (nptr[i] == ' ' || (nptr[i] >= 9 && nptr[i] <= 13))
i++;
if (nptr[i] == '-' || nptr[i] == '+')
{
if (nptr[i] == '-')
sign = -1;
i++;
}
while (nptr[i] >= '0' && nptr[i] <= '9')
{
res = res * 10 + (nptr[i] - '0');
i++;
}
return (res * sign);
}
void *ft_calloc(size_t nmemb, size_t size)
{
unsigned char *p;
int n;
int i;
p = malloc(nmemb * size);
if (p == NULL)
return (NULL);
else
{
i = 0;
n = nmemb * size;
while (n-- > 0)
p[i++] = '\0';
}
return (p);
}
int ft_isdigit_str(char *arg)
{
if (arg)
{
while (*arg)
{
if (*arg < '0' || *arg > '9')
return (0);
arg++;
}
}
return (1);
}