ft_substr.c
1 /* ************************************************************************** */ 2 /* */ 3 /* ::: :::::::: */ 4 /* ft_substr.c :+: :+: :+: */ 5 /* +:+ +:+ +:+ */ 6 /* By: abonnard <abonnard@student.42nice.fr> +#+ +:+ +#+ */ 7 /* +#+#+#+#+#+ +#+ */ 8 /* Created: 2024/11/05 12:14:10 by abonnard #+# #+# */ 9 /* Updated: 2024/11/05 12:23:20 by abonnard ### ########.fr */ 10 /* */ 11 /* ************************************************************************** */ 12 13 #include <stdlib.h> 14 15 char *ft_substr(char const *s, unsigned int start, size_t len) 16 { 17 char *str; 18 size_t i; 19 20 i = 0; 21 str = malloc(len + 1); 22 if (!str) 23 return (0); 24 while (i < len) 25 { 26 str[i] = s[start + i]; 27 i++; 28 } 29 str[i] = '\0'; 30 return (str); 31 }