39 lines
666 B
C
39 lines
666 B
C
/*
|
|
** 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);
|
|
}
|