Archived
1
0

strmapi done && split fix

This commit is contained in:
Adam Joly
2023-11-11 11:56:43 +01:00
parent f24566d838
commit 67ea55d5c7
4 changed files with 11 additions and 17 deletions

View File

@ -6,7 +6,7 @@
# By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ # # By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2023/11/01 11:03:22 by adjoly #+# #+# # # Created: 2023/11/01 11:03:22 by adjoly #+# #+# #
# Updated: 2023/11/11 11:12:02 by adjoly ### ########.fr # # Updated: 2023/11/11 11:49:54 by adjoly ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -46,6 +46,7 @@ SRCS = ft_atoi.c \
ft_putendl_fd.c \ ft_putendl_fd.c \
ft_strtrim.c \ ft_strtrim.c \
ft_split.c \ ft_split.c \
ft_strmapi.c \
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 16:02:26 by adjoly #+# #+# */ /* Created: 2023/11/01 16:02:26 by adjoly #+# #+# */
/* Updated: 2023/11/11 00:55:15 by adjoly ### ########.fr */ /* Updated: 2023/11/11 01:32:30 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,7 +18,9 @@ void *ft_calloc(size_t nmemb, size_t size)
void *result; void *result;
if (size != 0 && nmemb != 0 && (nmemb * size) / nmemb != size) if (size != 0 && nmemb != 0 && (nmemb * size) / nmemb != size)
return (malloc(0)); return (NULL);
if (nmemb == 0 || size == 0)
return (malloc(1));
result = malloc(size * nmemb); result = malloc(size * nmemb);
if (result == NULL) if (result == NULL)
return (NULL); return (NULL);

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 19:04:42 by adjoly #+# #+# */ /* Created: 2023/11/09 19:04:42 by adjoly #+# #+# */
/* Updated: 2023/11/11 11:15:37 by adjoly ### ########.fr */ /* Updated: 2023/11/11 11:27:49by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -59,7 +59,6 @@ char **ft_split(char const *s, char c)
char **result; char **result;
int i; int i;
int j; int j;
int k;
i = 0; i = 0;
j = 0; j = 0;
@ -75,17 +74,8 @@ char **ft_split(char const *s, char c)
j++; j++;
if (s[j] != '\0' && s[j] != c) if (s[j] != '\0' && s[j] != c)
{ {
k = 0; result[i] = ft_substr(s, j, ft_countletter(s + j, c));
result[i] = malloc((ft_countletter(&s[j], c) + 1) * sizeof(char)); j += ft_countletter(s + j, c);
if (result == NULL)
return (ft_freearr(result));
while (s[j] != c)
{
result[i][k] = s[j];
j++;
k++;
}
result[i][k] = '\0';
} }
i++; i++;
} }

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 10:06:03 by adjoly #+# #+# */ /* Created: 2023/11/01 10:06:03 by adjoly #+# #+# */
/* Updated: 2023/11/11 10:40:20 by adjoly ### ########.fr */ /* Updated: 2023/11/11 11:49:37 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -51,5 +51,6 @@ char *ft_strnstr(const char *big, const char *little, size_t len);
void ft_putendl_fd(char *s, int fd); void ft_putendl_fd(char *s, int fd);
char *ft_strtrim(char const *s1, char const *set); char *ft_strtrim(char const *s1, char const *set);
char **ft_split(char const *s, char c); char **ft_split(char const *s, char c);
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
#endif #endif