-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strdup.c
More file actions
36 lines (33 loc) · 1.19 KB
/
Copy pathft_strdup.c
File metadata and controls
36 lines (33 loc) · 1.19 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pruthann <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/14 16:51:53 by pruthann #+# #+# */
/* Updated: 2020/11/14 16:52:42 by pruthann ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *src)
{
char *newsrc;
char *temp;
int len;
len = 0;
while (src[len] != '\0')
len++;
newsrc = malloc((len + 1) * sizeof(*src));
if (newsrc == 0)
return (NULL);
temp = newsrc;
while (*src)
{
*newsrc = *src;
newsrc++;
src++;
}
*newsrc = '\0';
return (temp);
}