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.

76 lines
2.0 KiB

3 years ago
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchars.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/27 09:17:03 by narnaud #+# #+# */
/* Updated: 2021/11/17 09:57:53 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_print_char(int ch, t_opts *opts)
3 years ago
{
char c;
int ret;
3 years ago
c = (char)ch;
ret = 1;
if (opts->minus)
{
ft_putchar_fd(c, 1);
while (opts->width-- > 1 && ++ret)
ft_putchar_fd(' ', 1);
}
else
{
while (opts->width-- > 1 && ++ret)
ft_putchar_fd(' ', 1);
ft_putchar_fd(c, 1);
}
return (ret);
3 years ago
}
int ft_print_str(char *str, t_opts *opts)
3 years ago
{
int i;
char *formated;
3 years ago
i = 0;
if (!str)
{
if (!opts->dot || opts->precision >= 6)
str = "(null)";
else
str = "";
}
formated = str_opts_transform(str, opts);
while (formated[i])
ft_putchar_fd(formated[i++], 1);
free(formated);
3 years ago
return (i);
}
int va_print_char(va_list va_ch, const char *str, t_opts *opts)
3 years ago
{
(void)*str;
return (ft_print_char(va_arg(va_ch, int), opts));
3 years ago
}
int va_print_str(va_list va_str, const char *str, t_opts *opts)
3 years ago
{
(void)*str;
return (ft_print_str(va_arg(va_str, char *), opts));
3 years ago
}
int va_print_perc(va_list va, const char *str, t_opts *opts)
3 years ago
{
(void)*str;
(void)va;
ft_print_char('%', opts);
3 years ago
return (1);
}