39 lines
1.4 KiB
C
39 lines
1.4 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_substr.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/10/17 11:45:52 by kcolin #+# #+# */
|
|
/* Updated: 2024/10/17 11:58:18 by kcolin ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
#include <stdlib.h>
|
|
|
|
char *ft_substr(char const *s, unsigned int start, size_t len)
|
|
{
|
|
char *out;
|
|
|
|
out = malloc(sizeof(char) * len + 1);
|
|
if (out == NULL)
|
|
return (NULL);
|
|
ft_strlcpy(out, s + start, len + 1);
|
|
return (out);
|
|
}
|
|
|
|
/*
|
|
#include <stdio.h> // BAD
|
|
|
|
int main(void)
|
|
{
|
|
char *data = "This is a long test string.";
|
|
|
|
printf("'%s'\n", ft_substr(data, 0, 4));
|
|
printf("'%s'\n", ft_substr(data, 15, 4));
|
|
printf("'%s'\n", ft_substr(data, 15, 0));
|
|
printf("'%s'\n", ft_substr(data, 20, 20));
|
|
}
|
|
*/
|