-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf_utils.c
66 lines (59 loc) · 1.64 KB
/
ft_printf_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mohaben- <mohaben-@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/22 19:47:06 by mohaben- #+# #+# */
/* Updated: 2024/11/27 14:55:15 by mohaben- ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
t_flags ft_initializ_flags(void)
{
t_flags flag;
flag.hash = 0;
flag.plus = 0;
flag.space = 0;
flag.zero_padding = 0;
flag.precision = -1;
flag.left_align = 0;
flag.width = 0;
return (flag);
}
int ft_atoi(const char *str)
{
int sign;
long res;
sign = 1;
res = 0;
while (*str == 32 || (*str >= 9 && *str <= 13))
str++;
if (*str == '+' || *str == '-')
{
if (*str == '-')
sign = -1;
str++;
}
while (*str >= '0' && *str <= '9')
{
if (res > (9223372036854775807 - (*str - '0')) / 10)
{
if (sign == 1)
return (-1);
else if (sign == -1)
return (0);
}
res = res * 10 + (*str++ - '0');
}
return ((int)(res * sign));
}
int ft_strlen(const char *s)
{
int i;
i = 0;
while (s && s[i] != '\0')
i++;
return (i);
}