void		ft_printf_add_precision(t_pf *list)
{
	unsigned char		*n_str;
	int					i;
	int					j;

	j = -1;
	i = 0;
	if (ft_printf_atoi(list->buff) < 0)
		list->precision += 1;
	if (list->precision > list->len)
	{
		n_str = (unsigned char*)malloc(list->precision + 1);
		while (i < list->precision - list->len)
			n_str[i++] = '0';
		while (list->buff[++j])
			n_str[i + j] = list->buff[j];
		n_str[i + j] = '\0';
		free(list->buff);
		list->buff = n_str;
	}
	else if (list->len == 1 && list->buff[0] == '0' && list->precision == 0)
	{
		free(list->buff);
		list->buff = (unsigned char*)ft_printf_char_to_str('\0', list);
	}
	list->len = ft_printf_strlen(list->buff);
}
Exemple #2
0
/*                                                                            */
/* ************************************************************************** */

#include "ft_printf_struct.h"

int	set_printf_width(char *arg, va_list ap, t_printf_flags *flags)
{
	char		*tmp;
	int			nbr;

	tmp = arg;
	if (*tmp == '*' || (*tmp >= '0' && *tmp <= '9'))
	{
		if (*tmp == '*' && arg++)
		{
			nbr = va_arg(ap, int);
			if (nbr < 0)
			{
				nbr = -nbr;
				flags->FLAGS_DASH = 1;
			}
			flags->width = nbr;
		}
		else
			flags->width = ft_printf_atoi(&arg);
		if (flags->width)
			flags->setting = 1;
	}
	return (arg - tmp);
}