feat: added strdup and putptr
This commit is contained in:
parent
0f35f48c25
commit
2a34720f4d
2 changed files with 32 additions and 0 deletions
19
srcs/ft_strdup.c
Normal file
19
srcs/ft_strdup.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
char *ft_strdup(const char *s)
|
||||
{
|
||||
size_t len = 0;
|
||||
char *dup;
|
||||
size_t i;
|
||||
|
||||
while (s[len])
|
||||
len++;
|
||||
dup = (char *)malloc(len + 1);
|
||||
if (!dup)
|
||||
return NULL;
|
||||
for (i = 0; i < len; i++)
|
||||
dup[i] = s[i];
|
||||
dup[len] = '\0';
|
||||
return (dup);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue