ft_strdup: initial implementation
This commit is contained in:
parent
df37e074f3
commit
a20611c09a
3 changed files with 53 additions and 3 deletions
5
Makefile
5
Makefile
|
|
@ -6,7 +6,7 @@
|
|||
# By: kcolin <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/14 13:43:59 by kcolin #+# #+# #
|
||||
# Updated: 2024/10/17 10:21:34 by kcolin ### ########.fr #
|
||||
# Updated: 2024/10/17 10:52:23 by kcolin ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
|
@ -33,7 +33,8 @@ SOURCES = ft_isalpha.c \
|
|||
ft_memcmp.c \
|
||||
ft_strnstr.c \
|
||||
ft_atoi.c \
|
||||
ft_calloc.c
|
||||
ft_calloc.c \
|
||||
ft_strdup.c
|
||||
OBJECTS = $(SOURCES:.c=.o)
|
||||
CC = gcc
|
||||
|
||||
|
|
|
|||
47
ft_strdup.c
Normal file
47
ft_strdup.c
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/17 10:49:55 by kcolin #+# #+# */
|
||||
/* Updated: 2024/10/17 10:57:52 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
char *ft_strdup(const char *s)
|
||||
{
|
||||
char *dup;
|
||||
|
||||
dup = malloc(ft_strlen(s) + 1);
|
||||
if (dup == NULL)
|
||||
return (NULL);
|
||||
ft_strlcpy(dup, s, ft_strlen(s) + 1);
|
||||
return (dup);
|
||||
}
|
||||
|
||||
/*
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 1;
|
||||
if (argc > 1)
|
||||
{
|
||||
while (i < argc)
|
||||
{
|
||||
char *dup = ft_strdup(argv[i]);
|
||||
printf("%s\n", dup);
|
||||
free(dup);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
*/
|
||||
4
libft.h
4
libft.h
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/15 10:11:54 by kcolin #+# #+# */
|
||||
/* Updated: 2024/10/17 10:19:51 by kcolin ### ########.fr */
|
||||
/* Updated: 2024/10/17 11:03:30 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -46,4 +46,6 @@ int ft_atoi(const char *nptr);
|
|||
|
||||
void *ft_calloc(size_t nmemb, size_t size);
|
||||
|
||||
char *ft_strdup(const char *s);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue