Libft and ftprintf added

This commit is contained in:
Angel Ortigosa Perez
2025-11-15 10:31:47 +01:00
parent 5c40a00540
commit a4c1881930
54 changed files with 1809 additions and 105 deletions

41
lib/libft/ft_substr.c Normal file
View File

@@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/24 15:15:06 by aortigos #+# #+# */
/* Updated: 2023/10/23 18:29:42 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *x;
size_t i;
if (!s)
return (NULL);
if (ft_strlen(s) < start)
{
x = ft_calloc(1, sizeof(char));
if (!x)
return (NULL);
}
else
{
i = ft_strlen(s + start);
if (!(i < len))
i = len;
x = (char *)malloc((i + 1) * sizeof(char));
if (!x)
return (NULL);
x[i] = 0;
while (i-- > 0)
x[i] = s[start + i];
}
return (x);
}