Working on ft_split()
This commit is contained in:
parent
337475e022
commit
e5cd17c1b8
2 changed files with 77 additions and 2 deletions
74
ft_split_test.c
Normal file
74
ft_split_test.c
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_split_test.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/10/09 17:20:58 by lalgarra #+# #+# */
|
||||
/* Updated: 2025/10/09 17:35:12 by lalgarra ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static void ft_putstr_fd1(char *res, int fd)
|
||||
{
|
||||
if (res == NULL)
|
||||
ft_putstr_fd("-NULL-", fd);
|
||||
else
|
||||
ft_putstr_fd(res, fd);
|
||||
}
|
||||
|
||||
static void printres(char **res, int fd)
|
||||
{
|
||||
size_t idx;
|
||||
|
||||
idx = 0;
|
||||
while (res[idx] != NULL)
|
||||
{
|
||||
ft_putstr_fd1(res[idx], fd);
|
||||
ft_putstr_fd("], [", fd);
|
||||
}
|
||||
ft_putstr_fd1(res[idx], fd);
|
||||
}
|
||||
|
||||
static void freeres(char **res)
|
||||
{
|
||||
size_t idx;
|
||||
|
||||
idx = 0;
|
||||
while (res[idx] != NULL)
|
||||
free(res[idx]);
|
||||
free(res);
|
||||
}
|
||||
|
||||
static void test(char *prefix, char *str1, char c)
|
||||
{
|
||||
char **res;
|
||||
int fd;
|
||||
|
||||
fd = STDOUT_FILENO;
|
||||
ft_putstr_fd(prefix, fd);
|
||||
ft_putstr_fd("str1:[", fd);
|
||||
ft_putstr_fd1(str1, fd);
|
||||
ft_putstr_fd("], c:[", fd);
|
||||
ft_putchar_fd(c, fd);
|
||||
res = ft_split(str1, c);
|
||||
ft_putstr_fd("], result:{[", fd);
|
||||
printres(res, fd);
|
||||
freeres(res);
|
||||
ft_putendl_fd("]}", fd);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test("test 1: ", "Lorem", ' ');
|
||||
test("test 2: ", " Lorem ", ' ');
|
||||
test("test 3: ", " Lorem ", 'r');
|
||||
test("test 4: ", (void *)0, ' ');
|
||||
test("test 6: ", "Lorem", '\0');
|
||||
return (0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue