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);
|
||||||
|
}
|
||||||
13
srcs/vec/ft_putrptr.c
Normal file
13
srcs/vec/ft_putrptr.c
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_putptr(void *ptr)
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
count += ft_putstr("0x");
|
||||||
|
if (!ptr)
|
||||||
|
count += ft_putchar('0');
|
||||||
|
else
|
||||||
|
count += ft_putaddr((unsigned long)ptr);
|
||||||
|
return (count);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue