start strdup - problem with malloc -- to fix
This commit is contained in:
3
Makefile
3
Makefile
@ -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_bzero.o
Normal file
BIN
ft_bzero.o
Normal file
Binary file not shown.
BIN
ft_isalnum.o
Normal file
BIN
ft_isalnum.o
Normal file
Binary file not shown.
BIN
ft_isalpha.o
Normal file
BIN
ft_isalpha.o
Normal file
Binary file not shown.
BIN
ft_isascii.o
Normal file
BIN
ft_isascii.o
Normal file
Binary file not shown.
BIN
ft_isdigit.o
Normal file
BIN
ft_isdigit.o
Normal file
Binary file not shown.
BIN
ft_memcpy.o
Normal file
BIN
ft_memcpy.o
Normal file
Binary file not shown.
BIN
ft_memset.o
Normal file
BIN
ft_memset.o
Normal file
Binary file not shown.
BIN
ft_putchar_fd.o
Normal file
BIN
ft_putchar_fd.o
Normal file
Binary file not shown.
BIN
ft_putnbr_fd.o
Normal file
BIN
ft_putnbr_fd.o
Normal file
Binary file not shown.
BIN
ft_putstr_fd.o
Normal file
BIN
ft_putstr_fd.o
Normal file
Binary file not shown.
33
ft_strdup.c
Normal file
33
ft_strdup.c
Normal 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
BIN
ft_strdup.o
Normal file
Binary file not shown.
BIN
ft_strlcpy.o
Normal file
BIN
ft_strlcpy.o
Normal file
Binary file not shown.
BIN
ft_strlen.o
Normal file
BIN
ft_strlen.o
Normal file
Binary file not shown.
BIN
ft_substr.o
Normal file
BIN
ft_substr.o
Normal file
Binary file not shown.
BIN
ft_tolower.o
Normal file
BIN
ft_tolower.o
Normal file
Binary file not shown.
BIN
ft_toupper.o
Normal file
BIN
ft_toupper.o
Normal file
Binary file not shown.
3
libft.h
3
libft.h
@ -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);
|
||||||
|
Reference in New Issue
Block a user