Pushing from the vogsphere to the github

This commit is contained in:
Raphaël 2024-03-25 18:26:38 +00:00 committed by GitHub
parent d9986a5674
commit c86fe1ad3d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 2093 additions and 0 deletions

119
libft/get_next_line_utils.c Normal file
View file

@ -0,0 +1,119 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/18 17:14:47 by rparodi #+# #+# */
/* Updated: 2024/03/06 11:26:19 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/so_long.h"
size_t ft_strlen(char const *str)
{
size_t i;
i = 0;
if (str)
{
while (str[i])
i++;
}
return (i);
}
char *ft_strjoin(char *s1, char *s2, int i, int j)
{
char *temp;
if (!s1)
{
s1 = (char *)malloc(1);
s1[i] = '\0';
}
if (!s2 || !s1)
return (NULL);
temp = (char *)malloc((ft_strlen(s1) + ft_strlen(s2) + 1));
if (!temp)
return (NULL);
while (s1[i])
{
temp[i] = s1[i];
i++;
}
while (s2[++j])
temp[i + j] = s2[j];
temp[i + j] = '\0';
free(s1);
return (temp);
}
char *ft_get_line(char *str)
{
char *temp;
int i;
i = 0;
if (!str[i])
return (NULL);
while (str[i] && str[i] != '\n')
i++;
temp = (char *)malloc((i + 2));
if (!temp)
return (NULL);
i = 0;
while (str[i] && str[i] != '\n')
{
temp[i] = str[i];
i++;
}
if (str[i] == '\n')
{
temp[i] = str[i];
i++;
}
temp[i] = '\0';
return (temp);
}
char *ft_get_next(char *str)
{
char *temp;
int i;
int j;
i = 0;
while (str[i] && str[i] != '\n')
i++;
if (!str[i])
return (ft_free(str));
temp = (char *)malloc((ft_strlen(str) - i));
if (!temp)
return (NULL);
j = i + 1;
while (str[++i])
temp[i - j] = str[i];
temp[i - j] = '\0';
free(str);
return (temp);
}
int ft_index_strchr(const char *s, char c)
{
int i;
i = 0;
if (s)
{
while (s[i])
{
if (s[i] == c)
return (i + 1);
i++;
}
}
return (0);
}