-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strdup.c
More file actions
48 lines (43 loc) · 1.37 KB
/
ft_strdup.c
File metadata and controls
48 lines (43 loc) · 1.37 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tcakir-y <tcakir-y@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/11 14:29:51 by tcakir-y #+# #+# */
/* Updated: 2024/10/11 19:28:55 by tcakir-y ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s)
{
int len;
char *str;
int i;
len = 0;
while (s[len] != '\0')
len++;
str = (char *)malloc(sizeof(char) * (len + 1));
if (str == NULL)
return (NULL);
i = 0;
while (s[i] != '\0')
{
str[i] = s[i];
i++;
}
str[i] = '\0';
return (str);
}
//int main(void)
//{
// const char *str;
// const char *lib;
// const char *ft;
// str = "CODAAM!";
// lib = strdup(str);
// ft = ft_strdup(str);
// printf("Lib: %s\nft: %s\n", lib, ft);
// return (0);
//}