-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibft.c
100 lines (85 loc) · 2.34 KB
/
libft.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libft.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbutt <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/19 16:39:06 by mbutt #+# #+# */
/* Updated: 2019/05/22 15:46:53 by mbutt ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
/*
** Below are some libft functions
*/
/*
** ft_strdel frees memory and then sets the pointer to null. ft_strdel is used
** instead of free because values can still be accessed sometimes if they are
** freed using free(3)
*/
void ft_strdel(char **string)
{
if (string)
{
free(*string);
*string = NULL;
}
}
/*
** memdel frees memory and then sets the pointer to null, because values can
** still be accessed if freed with free(3).
*/
void ft_memdel(void **address)
{
if (address)
{
free(*address);
*address = NULL;
}
}
/*
** ft_putstr prints a string
*/
void ft_putstr(const char *string)
{
int i;
i = 0;
if (string[i])
while (string[i])
write(1, &string[i++], 1);
}
/*
** Copies string from source to destination and null terminates the destination
** string.
*/
char *ft_strcpy(char *dst, const char *src)
{
int i;
i = 0;
while (src[i])
{
dst[i] = src[i];
i++;
}
dst[i] = '\0';
return (dst);
}
/*
** Writes n number of 0 bytes to a string. Useful when the same variable is used
** to store different values. For example, if a variable called placeholder was
** used to temporarily store some value, which is then stored to a different
** variable, then once placeholder is done storing the values onto the new
** variable, values for placeholder will be set to 0, so characters from
** previous value will be completely removed.
*/
void ft_bzero(char *string)
{
int i;
i = 0;
while (string[i] != '\0')
{
string[i] = 0;
i++;
}
}