start strdup - problem with malloc -- to fix

This commit is contained in:
KeyZox committed 2023-11-03 23:14:18 +01:00
1 parent 1867e4d159
commit 4f8cb21f2a
21 files changed
+37 -2

No files matched your search

+2 -1
View File
@@ -6,7 +6,7 @@
# By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/11/01 11:03:22 by adjoly #+# #+# #
# Updated: 2023/11/03 19:10:18 by adjoly ### ########.fr #
# Updated: 2023/11/03 23:05:37 by adjoly ### ########.fr #
# #
# **************************************************************************** #
@@ -23,6 +23,7 @@ SRCS = ft_atoi.c \
ft_putchar_fd.c \
ft_putnbr_fd.c \
ft_putstr_fd.c \
ft_strdup.c \
ft_memcpy.c \
ft_memset.c \
ft_strlcpy.c \
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+33
View File
@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/03 22:57:39 by adjoly #+# #+# */
/* Updated: 2023/11/03 23:08:23 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s)
{
int i;
char *result;
int len;
i = 0;
len = ft_strlen(s);
result = malloc(sizeof(char) * len);
if (result == NULL)
return (NULL);
while (s[i])
{
result[i] = s[i];
i++;
}
result[i] = '\0';
return (result);
}
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+2 -1
View File
@@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 10:06:03 by adjoly #+# #+# */
/* Updated: 2023/11/03 15:57:10 by adjoly ### ########.fr */
/* Updated: 2023/11/03 23:06:30 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@@ -29,6 +29,7 @@ void *ft_memmove(void *dest, const void *src, size_t n);
void *ft_memcpy(void *dest, const void *src, size_t n);
void ft_putchar_fd(char c, int fd);
void ft_putnbr_fd(int n, int fd);
char *ft_strdup(const char *s);
void ft_putstr_fd(char *s, int fd);
char *ft_strchr(const char *s, int c);
size_t ft_strlcpy(char *dst, const char *src, size_t size);