Path: blob/master/philo_bonus/ft_substr_bonus.c
882 views
/* ************************************************************************** */1/* */2/* ::: :::::::: */3/* ft_substr_bonus.c :+: :+: :+: */4/* +:+ +:+ +:+ */5/* By: yabtaour <[email protected]> +#+ +:+ +#+ */6/* +#+#+#+#+#+ +#+ */7/* Created: 2022/05/23 00:08:26 by yabtaour #+# #+# */8/* Updated: 2022/05/23 00:08:28 by yabtaour ### ########.fr */9/* */10/* ************************************************************************** */11#include "philosophers_bonus.h"1213char *ft_substr(char *s, int start, size_t len)14{15char *ptr;16unsigned int i;17int end;1819i = 0;20end = len + start;21if (!s)22return (NULL);23ptr = (char *)malloc((len + 1) * sizeof(char));24if (!ptr)25return (NULL);26if (start <= ft_strlen(s))27{28while (start < end && s[start] != '\0')29{30ptr[i] = s[start];31i++;32start++;33}34}35ptr[i] = '\0';36return (ptr);37}383940