-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf_utils.c
More file actions
73 lines (65 loc) · 1.69 KB
/
ft_printf_utils.c
File metadata and controls
73 lines (65 loc) · 1.69 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fulloa-s <fulloa-s@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/03 16:41:28 by fulloa-s #+# #+# */
/* Updated: 2021/02/09 10:48:26 by fulloa-s ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void sign(int *c)
{
if ((*c % 2) == 0)
*c = 1;
else
*c = -1;
}
int ft_atoi(char *str)
{
int i;
int c;
int res;
res = 0;
i = 0;
c = 0;
while (str[i] && (str[i] == ' ' || str[i] == '\t' || str[i] == '\n'
|| str[i] == '\v' || str[i] == '\f' || str[i] == '\r'))
i++;
while (str[i] && (str[i] == '-' || str[i] == '+'))
{
if (str[i] == '-')
c++;
i++;
}
while (str[i] && (str[i] >= '0' && str[i] <= '9'))
{
res = res * 10;
res = res + (str[i] - '0');
i++;
}
sign(&c);
return (res * c);
}
int ft_strlen(char *str)
{
int i;
if (!str)
return (-1);
i = 0;
while (str[i])
i++;
return (i);
}
char *ft_strdup(char *s1)
{
size_t x;
char *ptr;
x = ft_strlen(s1) + 1;
if (!(ptr = (char *)malloc(sizeof(char) * x)))
return (NULL);
ft_memcpy(ptr, s1, x);
return (ptr);
}