예제 #1
0
static void			get_size_number_string(long long nb, t_arg *opt, char **s)
{
	if (opt->is_u)
		*s = ft_itobase((unsigned long long)nb, (unsigned long long)opt->base);
	else
		*s = ft_lltoa((long long)nb);
}
예제 #2
0
파일: print.c 프로젝트: n0izn0iz/ft_printf
void					print_int(va_list *valist, t_spec_flags *opts)
{
	char		*str;
	intmax_t	nbr;
	int			len;

	nbr = printf_intcast(valist, opts);
	str = ft_lltoa(nbr);
	len = MAX((int)ft_strlen(nbr < 0 ? str + 1 : str), \
			opts->precision) + (opts->space || opts->plus);
	if (!opts->minus)
		ft_putnchar(opts->width - len, opts->zero ? '0' : ' ');
	if (nbr < 0)
		ft_putchar('-');
	if (opts->plus && *str != '-')
		ft_putchar('+');
	else if (opts->space && *str != '-')
		ft_putchar(' ');
	ft_putnchar(opts->precision - ft_strlen(nbr < 0 ? str + 1 : str), '0');
	if (nbr != 0 || !opts->precision_set || opts->precision > 0)
		ft_putstr(nbr < 0 ? str + 1 : str);
	if (opts->minus)
		ft_putnchar(opts->width - len, ' ');
	free(str);
}
예제 #3
0
static char	*fill_word(char type, long long nbr)
{
	char *word;

	word = NULL;
	if (type == 'd' || type == 'D' || type == 'i')
		word = ft_lltoa(nbr);
	else if (type == 'u' || type == 'U')
		word = ft_ulltoa((unsigned long long)nbr);
	else if (type == 'x' || type == 'p')
		word = ft_lltoah(nbr, 1);
	else if (type == 'X')
		word = ft_lltoah(nbr, 2);
	else if (type == 'o' || type == 'O')
		word = ft_lltoao(nbr);
	else if (type == 'b')
		word = ft_lltoab(nbr);
	return (word);
}