Files
42-ft_printf/bonus/print_str_bonus.c
2025-11-21 15:57:06 +01:00

41 lines
1.5 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print_str_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/17 12:02:03 by dgaillet #+# #+# */
/* Updated: 2025/11/21 15:32:08 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include "ft_printf_bonus.h"
int print_str(t_arg *arg, char *str)
{
int count;
count = 0;
if (!str)
{
if (arg->dot < 6 && arg->dot >= 0)
return (print_chars(arg->padding, ' '));
if (arg->padding > 6)
count += print_chars(arg->padding - 6, ' ');
if (write(1, "(null)", 6) < 0)
return (-10000);
return (count + 6);
}
if (arg->dot > (int) ft_strlen(str) || arg->dot < 0)
arg->dot = ft_strlen(str);
if (arg->padding > 0)
count += print_chars(arg->padding - arg->dot, ' ');
else if (!str[0] && arg->space > 0)
return (write(1, " ", 1));
if (write(1, str, arg->dot) < 0)
return (-10000);
return (count + arg->dot);
}