-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.c
44 lines (40 loc) · 1.37 KB
/
utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dnishsha <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/19 14:56:41 by dnishsha #+# #+# */
/* Updated: 2023/07/19 14:56:43 by dnishsha ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void print_error(char *msg)
{
ft_printf("%s\n", msg);
exit(1);
}
int ft_atoi(const char *str)
{
int num;
int sign;
sign = 1;
num = 0;
if (!*str)
print_error("ERROR IN INPUTS");
if (*str && *str == '-' && (*(str + 1) <= '9' && *(str + 1) >= '0'))
{
sign = -1;
str ++;
}
while (*str)
{
if (*str > '9' || *str < '0')
print_error("ERROR IN INPUTS");
num *= 10;
num += *str - '0';
str ++;
}
return (num * (sign));
}