Projet de l'école 42 : Printf
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

71 lines
1.8 KiB

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_chars.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/27 09:17:03 by narnaud #+# #+# */
/* Updated: 2023/04/13 12:14:39 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_print_char(int ch, t_opts *opts)
{
char c;
char *ret;
int len;
c = (char)ch;
if (opts->width < 1)
len = 1;
else
len = opts->width;
ret = ft_calloc(len + 1, sizeof(char));
if (opts->minus)
{
ret[0] = c;
while (opts->width-- > 1)
ret[opts->width] = ' ';
}
else
{
ret[len - 1] = c;
while (opts->width-- > 1)
ret[opts->width - 1] = ' ';
}
add_string(ret, len);
}
void ft_print_str(char *str, t_opts *opts)
{
char *ret;
if (!str)
{
if (!opts->dot || opts->precision >= 6)
str = "(null)";
else
str = "";
}
ret = str_opts_transform(str, opts);
add_string(ret, ft_strlen(ret));
}
void va_print_char(va_list va_ch, t_opts *opts)
{
ft_print_char(va_arg(va_ch, int), opts);
}
void va_print_str(va_list va_str, t_opts *opts)
{
ft_print_str(va_arg(va_str, char *), opts);
}
void va_print_perc(va_list va, t_opts *opts)
{
(void)va;
ft_print_char('%', opts);
}