-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc_utils.c
86 lines (76 loc) · 1.86 KB
/
func_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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* func_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: achane-l <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/14 12:05:50 by achane-l #+# #+# */
/* Updated: 2021/07/14 12:05:53 by achane-l ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void append_char(char **str, char c)
{
char *new_str;
int i;
int j;
i = 0;
j = 0;
new_str = malloc(ft_strlen(*str) + 2);
if (new_str == NULL)
return ;
new_str[i++] = c;
while ((*str)[j] != 0)
new_str[i++] = (*str)[j++];
new_str[i] = 0;
free(*str);
*str = new_str;
}
int ft_strlen(char *str)
{
int i;
i = 0;
if (!str)
return (i);
while (str[i])
i++;
return (i);
}
void putstr(char *str, t_flags *flags)
{
int i;
i = 0;
while (str != NULL && str[i])
write(1, &str[i++], 1);
if (i == 0 && flags->type_conv == 'c')
{
write (1, "\0", 1);
i++;
}
flags->char_count += i;
free(str);
}
char *ft_strdup(const char *source)
{
char *str;
int len;
len = ft_strlen((char *)source);
str = (char *)malloc((len + 1) * sizeof(char));
if (!str)
return (NULL);
str[len] = '\0';
while (len--)
str[len] = source[len];
return (str);
}
int ft_is_in(char *str, char c)
{
while (*str)
{
if (*str == c)
return (1);
str++;
}
return (0);
}