mirror of
https://github.com/Ladebeze66/libft.git
synced 2025-12-13 04:36:55 +01:00
38 lines
1.2 KiB
C
Executable File
38 lines
1.2 KiB
C
Executable File
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_substr.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/02/13 15:40:49 by fgras-ca #+# #+# */
|
|
/* Updated: 2023/11/14 17:07:20 by fgras-ca ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
char *ft_substr(char const *s, unsigned int start, size_t len)
|
|
{
|
|
char *new_s;
|
|
size_t i;
|
|
size_t j;
|
|
|
|
new_s = (char *)malloc(sizeof(char) * (len + 1));
|
|
if (!s || !new_s)
|
|
return (NULL);
|
|
i = 0;
|
|
j = 0;
|
|
while (s[i])
|
|
{
|
|
if (i >= start && j < len)
|
|
{
|
|
new_s[j] = s[i];
|
|
j++;
|
|
}
|
|
i++;
|
|
}
|
|
new_s[j] = '\0';
|
|
return (new_s);
|
|
}
|