Files
cub3d/lib/libft/ft_substr.c
Angel Ortigosa Perez a4c1881930 Libft and ftprintf added
2025-11-15 10:31:47 +01:00

42 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/24 15:15:06 by aortigos #+# #+# */
/* Updated: 2023/10/23 18:29:42 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *x;
size_t i;
if (!s)
return (NULL);
if (ft_strlen(s) < start)
{
x = ft_calloc(1, sizeof(char));
if (!x)
return (NULL);
}
else
{
i = ft_strlen(s + start);
if (!(i < len))
i = len;
x = (char *)malloc((i + 1) * sizeof(char));
if (!x)
return (NULL);
x[i] = 0;
while (i-- > 0)
x[i] = s[start + i];
}
return (x);
}