51 lines
1.5 KiB
C
51 lines
1.5 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_substr.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2019/11/25 14:01:58 by hulamy #+# #+# */
|
|
/* Updated: 2019/11/25 14:02:01 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)
|
|
{
|
|
char *str;
|
|
size_t i;
|
|
|
|
if (!s)
|
|
return (NULL);
|
|
if (!(str = (char *)malloc(sizeof(char) * (len + 1))))
|
|
return (NULL);
|
|
str[len] = '\0';
|
|
i = 0;
|
|
while (i < len)
|
|
str[i++] = s[start++];
|
|
return (str);
|
|
}
|