bonus started
This commit is contained in:
77
get_next_line_utils_bonus.c
Normal file
77
get_next_line_utils_bonus.c
Normal file
@@ -0,0 +1,77 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* get_next_line_utils_bonus.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/11/24 16:04:39 by dgaillet #+# #+# */
|
||||
/* Updated: 2025/11/24 16:12:37 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
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 && s2[j])
|
||||
{
|
||||
str[i + j] = s2[j];
|
||||
j++;
|
||||
}
|
||||
str[i + j] = '\0';
|
||||
free((void *) s1);
|
||||
return (str);
|
||||
}
|
||||
|
||||
char *ft_strdup(const char *s)
|
||||
{
|
||||
char *dest;
|
||||
int i;
|
||||
|
||||
dest = malloc(sizeof(char) *(ft_strlen(s) + 1));
|
||||
if (!dest)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (s[i])
|
||||
{
|
||||
dest[i] = s[i];
|
||||
i++;
|
||||
}
|
||||
dest[i] = '\0';
|
||||
return (dest);
|
||||
}
|
||||
|
||||
void ft_bzero(void *s, size_t n)
|
||||
{
|
||||
while (n > 0)
|
||||
{
|
||||
*((unsigned char *) s) = '\0';
|
||||
s++;
|
||||
n--;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user