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.
 
 

69 lines
2.0 KiB

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_x.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/27 09:54:24 by narnaud #+# #+# */
/* Updated: 2021/11/17 10:24:24 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_print_x(unsigned int n, t_opts *opts)
{
char *raw;
char *nbr;
char *tmp;
int ret;
raw = ft_itox((unsigned long int)n, "0123456789abcdef");
if (opts->hash && n != 0)
{
tmp = raw;
raw = ft_strjoin("0x", raw);
free(tmp);
}
nbr = uint_opts_transform(n, raw, opts);
opts->dot = 0;
ret = ft_print_str(nbr, opts);
free(raw);
free(nbr);
return (ret);
}
int ft_print_x_cap(unsigned int n, t_opts *opts)
{
char *raw;
char *tmp;
char *nbr;
int ret;
raw = ft_itox((unsigned long int)n, "0123456789ABCDEF");
if (opts->hash && n != 0)
{
tmp = raw;
raw = ft_strjoin("0X", raw);
free(tmp);
}
nbr = uint_opts_transform(n, raw, opts);
opts->dot = 0;
ret = ft_print_str(nbr, opts);
free(raw);
free(nbr);
return (ret);
}
int va_print_x(va_list va_uint, const char *str, t_opts *opts)
{
(void)*str;
return (ft_print_x(va_arg(va_uint, unsigned int), opts));
}
int va_print_x_cap(va_list va_uint, const char *str, t_opts *opts)
{
(void)*str;
return (ft_print_x_cap(va_arg(va_uint, unsigned int), opts));
}