fixe substr quand start commence apres la fin de s
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:01:58 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/26 16:18:25 by hulamy ### ########.fr */
|
||||
/* Updated: 2019/11/27 19:54:09 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -40,11 +40,13 @@ char *ft_substr(char const *s, unsigned int start, size_t len)
|
||||
|
||||
if (!s)
|
||||
return (NULL);
|
||||
if (ft_strlen(s) < start)
|
||||
return ("");
|
||||
if (!(str = (char *)malloc(sizeof(char) * (len + 1))))
|
||||
return (NULL);
|
||||
str[len] = '\0';
|
||||
i = 0;
|
||||
while (i < len)
|
||||
while (i < len && s[start])
|
||||
str[i++] = s[start++];
|
||||
str[i] = '\0';
|
||||
return (str);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user