Files
cub3d/lib/gnl/get_next_line_utils.c
2025-11-16 20:41:09 +01:00

70 lines
1.7 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/15 18:37:57 by aortigos #+# #+# */
/* Updated: 2025/11/16 20:40:51 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
char *ft_get_line(char *left_str)
{
int i;
char *str;
i = 0;
if (!left_str[i])
return (NULL);
while (left_str[i] && left_str[i] != '\n')
i++;
str = (char *)malloc(sizeof(char) * (i + 2));
if (!str)
return (NULL);
i = 0;
while (left_str[i] && left_str[i] != '\n')
{
str[i] = left_str[i];
i++;
}
if (left_str[i] == '\n')
{
str[i] = left_str[i];
i++;
}
str[i] = '\0';
return (str);
}
char *ft_new_left_str(char *left_str)
{
int i;
int j;
char *str;
i = 0;
while (left_str[i] && left_str[i] != '\n')
i++;
if (!left_str[i])
{
free(left_str);
return (NULL);
}
str = (char *)malloc(sizeof(char) * (ft_strlen(left_str) - i + 1));
if (!str)
{
return (NULL);
}
i++;
j = 0;
while (left_str[i])
str[j++] = left_str[i++];
str[j] = '\0';
free(left_str);
return (str);
}