Archived
1
0
This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
libft/ft_substr.c
2023-11-09 18:28:02 +01:00

39 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/02 17:59:58 by adjoly #+# #+# */
/* Updated: 2023/11/09 15:02:46 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
size_t i;
char *result;
i = 0;
if (s == NULL)
return (NULL);
if (start > ft_strlen(s))
{
result = calloc(1, 1);
return (result);
}
result = malloc(((ft_strlen(s) - len) + 1) * sizeof(char));
if (result == NULL)
return (NULL);
while (i < len && s[start + i])
{
result[i] = s[start + i];
i++;
}
result[i] = '\0';
return (result);
}