mise a jour functions strtrim strmapi et substr

This commit is contained in:
Hugo LAMY
2019-11-25 13:52:27 +01:00
parent c29be1b311
commit 500c4516b1
4 changed files with 103 additions and 51 deletions

View File

@@ -1,19 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/19 17:20:51 by hulamy #+# #+# */
/* Updated: 2019/11/19 17:24:10 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** create a copy of a portion of s, begining at start and of length len
*/
/*
** #include <libc.h>
**
** char *ft_substr(char const *s, unsigned int start, size_t len);
**
** int main(int ac, char **av)
** {
** char *str;
**
** if (ac != 4)
** return (0);
** str = ft_substr(av[1], atoi(av[2]), atoi(av[3]));
** printf("%s\n",str);
** return (0);
** }
*/
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
@@ -23,8 +28,9 @@ char *ft_substr(char const *s, unsigned int start, size_t len)
if (!s)
return (NULL);
if (!(str = ft_strnew(len)))
if (!(str = (char *)malloc(sizeof(char) * (len + 1))))
return (NULL);
str[len] = '\0';
i = 0;
while (i < len)
str[i++] = s[start++];