libft_testing/ft_substr_test.c
2025-10-08 19:24:03 +02:00

76 lines
1.9 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr_test.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/08 18:44:25 by lalgarra #+# #+# */
/* Updated: 2025/10/08 19:17:14 by lalgarra ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdio.h>
#include <string.h>
static void test(char *prefix, char buff[], unsigned int start, size_t len)
{
char *res;
int fd;
fd = STDOUT_FILENO;
ft_putstr_fd(prefix, fd);
ft_putstr_fd("buff:[", fd);
ft_putstr_fd(buff, fd);
ft_putstr_fd("], start:[", fd);
ft_putnbr_fd(start, fd);
ft_putstr_fd("], len:[", fd);
ft_putnbr_fd(len, fd);
res = ft_substr(buff, start, len);
ft_putstr_fd("], result:[", fd);
if (res == NULL)
ft_putstr_fd("-NULL-", fd);
else
ft_putstr_fd(res, fd);
free(res);
ft_putendl_fd("]", fd);
}
static void do_test1(void)
{
test("test 1: ", "Lorem ipsum", 0, 10);
}
static void do_test2(void)
{
test("test 2: ", "Lorem ipsum", 7, 10);
}
static void do_test3(void)
{
test("test 3: ", "Lorem ipsum", 12, 10);
}
/*
static void zero(char buff[])
{
ft_bzero(buff, 128);
}
static void do_test2(char buff[])
{
zero(buff);
ft_strlcpy(buff, "+-50", 5);
}
*/
int main(void)
{
//char buff[128];
do_test1();
do_test2();
do_test3();
return (0);
}