Archived
1
0

finish correc

This commit is contained in:
Adam Joly
2023-11-13 17:04:34 +01:00
parent b00680b8f6
commit 59ffcec0f0
9 changed files with 60 additions and 42 deletions

View File

@ -6,7 +6,7 @@
# By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/11/01 11:03:22 by adjoly #+# #+# #
# Updated: 2023/11/12 09:08:30 by adjoly ### ########.fr #
# Updated: 2023/11/12 14:03:19 by adjoly ### ########.fr #
# #
# **************************************************************************** #
@ -75,6 +75,10 @@ $(NAME): $(OBJS)
all: $(NAME)
so:
$(CC) -nostartfiles -fPIC $(CFLAGS) $(SRCS) $(SRCS_BONUS)
gcc -nostartfiles -shared -o libft.so $(OBJS) $(OBJS_BONUS)
bonus: $(OBJS_BONUS)
ar -rcs $(NAME) $(OBJS_BONUS)

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 18:05:14 by adjoly #+# #+# */
/* Updated: 2023/11/11 18:19:34 by adjoly ### ########.fr */
/* Updated: 2023/11/12 16:19:59 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,7 +17,7 @@ void ft_lstclear(t_list **lst, void (*del)(void *))
t_list *tmp;
tmp = NULL;
while (*lst && lst)
while (lst && *lst && del)
{
tmp = (*lst)->next;
ft_lstdelone((*lst), del);

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 17:59:39 by adjoly #+# #+# */
/* Updated: 2023/11/11 18:17:04 by adjoly ### ########.fr */
/* Updated: 2023/11/12 15:33:38 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,7 +14,7 @@
void ft_lstdelone(t_list *lst, void (*del)(void *))
{
if (lst == NULL)
if (lst == NULL || del == NULL)
return ;
del(lst->content);
free(lst);

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/12 09:14:19 by adjoly #+# #+# */
/* Updated: 2023/11/12 09:17:04 by adjoly ### ########.fr */
/* Updated: 2023/11/12 16:28:35 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -43,41 +43,52 @@ static void *ft_freearr(char **arr)
int i;
i = 0;
free(arr[i]);
while (arr[i])
{
i++;
free(arr[i]);
i++;
}
free(arr);
return (NULL);
}
char **ft_split(char const *s, char c)
char **ft_split_to_result(char **tab, char const *s, char c)
{
int w_count;
char **result;
int i;
int j;
int k;
i = -1;
i = 0;
j = 0;
while (s[i])
{
if (s[i] != c)
{
k = 0;
tab[j] = ft_calloc(ft_countletter(&s[i], c) + 1, sizeof(char));
if (!tab[j])
return (ft_freearr(tab));
while (s[i] && s[i] != c)
tab[j][k++] = s [i++];
tab[j][k] = '\0';
j++;
}
else
i++;
}
tab[j] = NULL;
return (tab);
}
char **ft_split(char const *s, char c)
{
char **result;
if (s == NULL)
return (NULL);
w_count = ft_countword(s, c);
result = malloc((w_count + 1) * sizeof(char *));
if (result == NULL)
return (ft_freearr(result));
while (++i < w_count)
{
while (s[j] == c)
j++;
if (s[j] != '\0' && s[j] != c)
{
result[i] = ft_substr(s, j, ft_countletter(s + j, c));
j += ft_countletter(s + j, c);
}
}
result[i] = NULL;
result = ft_calloc(ft_countword(s, c) + 1, sizeof(char *));
if (!result)
return (NULL);
result = ft_split_to_result(result, s, c);
return (result);
}

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 14:15:30 by adjoly #+# #+# */
/* Updated: 2023/11/11 15:08:03 by adjoly ### ########.fr */
/* Updated: 2023/11/12 13:59:23 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,6 +17,8 @@ void ft_striteri(char *s, void (*f)(unsigned int, char *))
int i;
i = 0;
if (s == NULL || f == NULL)
return ;
while (s[i])
{
f(i, &s[i]);

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/04 13:44:09 by adjoly #+# #+# */
/* Updated: 2023/11/11 01:26:47 by adjoly ### ########.fr */
/* Updated: 2023/11/12 16:18:45 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,9 +20,9 @@ char *ft_strjoin(char const *s1, char const *s2)
i = 0;
j = 0;
if (s1 == NULL && s2 == NULL)
if (s1 == NULL || s2 == NULL)
return (NULL);
result = malloc((ft_strlen(s1) + ft_strlen(s2) + 1) * sizeof(char));
result = ft_calloc((ft_strlen(s1) + ft_strlen(s2) + 1), sizeof(char));
if (result == NULL)
return (NULL);
while (s1[i])

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 11:44:24 by adjoly #+# #+# */
/* Updated: 2023/11/11 11:50:17 by adjoly ### ########.fr */
/* Updated: 2023/11/13 16:14:32 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,9 +18,11 @@ char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
char *res;
i = 0;
if (s == NULL)
if (!s || !f)
return (NULL);
res = ft_calloc((ft_strlen(s) + 1), sizeof(char));
if (res == NULL)
return (NULL);
res = malloc((ft_strlen(s) + 1) * sizeof(char));
while (s[i])
{
res[i] = f(i, s[i]);

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/08 16:02:17 by adjoly #+# #+# */
/* Updated: 2023/11/09 13:58:30 by adjoly ### ########.fr */
/* Updated: 2023/11/12 16:17:28 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,15 +18,14 @@ char *ft_strnstr(const char *big, const char *little, size_t len)
size_t j;
i = 0;
j = 0;
if (!little || big == little)
if (!big && len == 0)
return (NULL);
if (*little == '\0' || little == big)
return ((char *)big);
if (len <= 0)
return (0);
while (i < len && big[i])
{
j = 0;
while (i + j < len && big[i + j] == little[j])
while (big[i + j] == little[j] && little[j] && big[i] && i + j < len)
j++;
if (little[j] == 0)
return ((char *)big + i);

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/02 17:59:58 by adjoly #+# #+# */
/* Updated: 2023/11/11 01:03:32 by adjoly ### ########.fr */
/* Updated: 2023/11/13 16:22:26 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -23,7 +23,7 @@ char *ft_substr(char const *s, unsigned int start, size_t len)
if (len >= ft_strlen(s))
len = ft_strlen(s) - start;
if (len == 0 || start >= ft_strlen(s))
return (calloc(1, 1));
return (ft_calloc(1, 1));
result = malloc((len + 1) * sizeof(char));
if (result == NULL)
return (NULL);