Browse Source

strlcat

master
Elouan MARTINET 4 years ago
parent
commit
a890c10202
  1. 2
      Makefile
  2. 35
      ft_strlcat.c
  3. 27
      ft_strnlen.c
  4. 1
      libft.h

2
Makefile

@ -25,9 +25,11 @@ SRC := \
ft_strcpy.c \
ft_strdup.c \
ft_strlen.c \
ft_strlcat.c \
ft_strncat.c \
ft_strncmp.c \
ft_strncpy.c \
ft_strnlen.c \
ft_strnstr.c \
ft_strrchr.c \
ft_strstr.c \

35
ft_strlcat.c

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/08 14:37:30 by emartine #+# #+# */
/* Updated: 2017/11/08 14:37:33 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
size_t dsti;
size_t srci;
dsti = ft_strnlen(dst, size);
if (dsti == size)
return (size);
srci = 0;
while (dsti < size)
{
dst[dsti] = src[srci];
if (src[srci] == '\0')
return (dsti - 1);
dsti++;
}
dst[size - 1] = '\0';
while (src[srci] != '\0')
srci++;
return (size + srci - 1);
}

27
ft_strnlen.c

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/08 14:47:26 by emartine #+# #+# */
/* Updated: 2017/11/08 14:47:28 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strnlen(const char *str, size_t size)
{
size_t i;
i = 0;
while (i < size)
{
if (str[i] == '\0')
return (i);
i++;
}
return (size);
}

1
libft.h

@ -71,6 +71,7 @@ void ft_putstr_fd(char const *s, int fd);
void ft_putendl_fd(char const *s, int fd);
void ft_putnbr_fd(int n, int fd);
int ft_isspace(int c);
size_t ft_strnlen(const char *str, size_t maxlen);
typedef struct s_list
{

Loading…
Cancel
Save