GNL with static buf worked. Next step, find a way to catch multiple nl when they're in the same buf

This commit is contained in:
David Gailleton
2025-11-21 19:07:39 +01:00
parent e7d0e929b3
commit 2b7dad9c15
3 changed files with 174 additions and 4 deletions

View File

@@ -6,7 +6,84 @@
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/21 17:21:38 by dgaillet #+# #+# */
/* Updated: 2025/11/21 17:21:49 by dgaillet ### ########lyon.fr */
/* Updated: 2025/11/21 18:57:06 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
int index_of_nl(char *str, int limit)
{
int i;
i = 0;
while (i < limit)
{
if (str[i] == '\n')
return (i);
i++;
}
return (-1);
}
size_t ft_strlen(const char *s)
{
size_t i;
i = 0;
while (s[i])
i++;
return (i);
}
char *ft_strjoin_new(char const *s1, char const *s2, size_t limit)
{
char *str;
size_t i;
size_t j;
str = malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1));
if (!str)
return (NULL);
i = 0;
j = 0;
while (s1[i])
{
str[i] = s1[i];
i++;
}
while (j <= limit)
{
str[i + j] = s2[j];
j++;
}
str[i + j] = '\0';
free((void *) s1);
return (str);
}
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);
}