first commit of v2 ft_printf

This commit is contained in:
2025-11-17 11:26:34 +01:00
commit 506d90d9c1
49 changed files with 1626 additions and 0 deletions

39
42-libft/ft_substr.c Normal file
View File

@@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/06 13:20:55 by dgaillet #+# #+# */
/* Updated: 2025/11/12 13:51:23 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
size_t i;
char *sub_str;
size_t s_len;
if (!s)
return (NULL);
s_len = ft_strlen(s);
if (start > s_len)
len = 0;
else if (s_len < (start + len))
len = s_len - start;
sub_str = malloc(sizeof(char) * (len + 1));
if (!sub_str)
return (NULL);
i = 0;
while (i < len)
{
sub_str[i] = s[start + i];
i++;
}
sub_str[i] = '\0';
return (sub_str);
}