-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
36 lines (32 loc) · 1.32 KB
/
ft_strdup.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bnidia <bnidia@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/13 03:19:21 by bnidia #+# #+# */
/* Updated: 2021/10/25 19:36:36 by bnidia ### ########.fr */
/* */
/* ************************************************************************** */
/* ft_strdup
** Duplicate string s. Memory for the new string is obtained with malloc,
** and can be freed with free
** Return Value
** A pointer to the duplicated string. NULL if insufficient memory
** was available
*/
#include "libft.h"
char *ft_strdup(const char *str)
{
char *cpy;
size_t i;
cpy = malloc(sizeof(char) * ft_strlen(str) + 1);
if (!(cpy))
return (NULL);
i = -1;
while (str[++i])
cpy[i] = str[i];
cpy[i] = '\0';
return (cpy);
}