push_swap/libft/ft_substr.c
2024-04-20 14:48:16 +02:00

32 lines
1.3 KiB
C
Executable file

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 13:54:42 by rparodi #+# #+# */
/* Updated: 2024/04/17 19:45:46 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/push_swap.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
size_t i;
size_t j;
char *str;
i = start;
if (start >= ft_len(s))
return (ft_strdup(""));
if (len + start > (ft_len(s)))
len = ft_len(s) - start;
j = 0;
str = (char *)malloc(len + 1);
if (!str || !s)
return (free(str), ft_strdup(""));
ft_strlcpy(str, s + start, len + 1);
return (str);
}