36 lines
1.3 KiB
C
36 lines
1.3 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_substr.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2022/09/28 18:53:44 by cchauvet #+# #+# */
|
|
/* Updated: 2022/10/05 20:53:19 by cchauvet ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
char *ft_substr(char const *s, unsigned int start, size_t len)
|
|
{
|
|
ssize_t size;
|
|
char *ptr;
|
|
|
|
if (s == NULL)
|
|
return (NULL);
|
|
size = ft_strlen(s);
|
|
size -= start;
|
|
if (size < 0)
|
|
size = 0;
|
|
if ((size_t)size > len)
|
|
size = len;
|
|
ptr = malloc((size + 1) * sizeof(char));
|
|
if (ptr == NULL)
|
|
return (NULL);
|
|
ptr[size] = '\0';
|
|
while (size-- > 0)
|
|
ptr[size] = s[start + size];
|
|
return (ptr);
|
|
}
|