1
0

start strdup - problem with malloc -- to fix

This commit is contained in:
2023-11-03 23:14:18 +01:00
parent 1867e4d159
commit 4f8cb21f2a
21 changed files with 37 additions and 2 deletions

View File

@ -6,7 +6,7 @@
# By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ # # By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2023/11/01 11:03:22 by adjoly #+# #+# # # 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_putchar_fd.c \
ft_putnbr_fd.c \ ft_putnbr_fd.c \
ft_putstr_fd.c \ ft_putstr_fd.c \
ft_strdup.c \
ft_memcpy.c \ ft_memcpy.c \
ft_memset.c \ ft_memset.c \
ft_strlcpy.c \ ft_strlcpy.c \

BIN
ft_atoi.o Normal file

Binary file not shown.

BIN
ft_bzero.o Normal file

Binary file not shown.

BIN
ft_isalnum.o Normal file

Binary file not shown.

BIN
ft_isalpha.o Normal file

Binary file not shown.

BIN
ft_isascii.o Normal file

Binary file not shown.

BIN
ft_isdigit.o Normal file

Binary file not shown.

BIN
ft_memcpy.o Normal file

Binary file not shown.

BIN
ft_memset.o Normal file

Binary file not shown.

BIN
ft_putchar_fd.o Normal file

Binary file not shown.

BIN
ft_putnbr_fd.o Normal file

Binary file not shown.

BIN
ft_putstr_fd.o Normal file

Binary file not shown.

33
ft_strdup.c Normal file
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
ft_strdup.o Normal file

Binary file not shown.

BIN
ft_strlcpy.o Normal file

Binary file not shown.

BIN
ft_strlen.o Normal file

Binary file not shown.

BIN
ft_substr.o Normal file

Binary file not shown.

BIN
ft_tolower.o Normal file

Binary file not shown.

BIN
ft_toupper.o Normal file

Binary file not shown.

BIN
libft.a Normal file

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 10:06:03 by adjoly #+# #+# */ /* 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_memcpy(void *dest, const void *src, size_t n);
void ft_putchar_fd(char c, int fd); void ft_putchar_fd(char c, int fd);
void ft_putnbr_fd(int n, int fd); void ft_putnbr_fd(int n, int fd);
char *ft_strdup(const char *s);
void ft_putstr_fd(char *s, int fd); void ft_putstr_fd(char *s, int fd);
char *ft_strchr(const char *s, int c); char *ft_strchr(const char *s, int c);
size_t ft_strlcpy(char *dst, const char *src, size_t size); size_t ft_strlcpy(char *dst, const char *src, size_t size);