Skip to content

Commit

Permalink
bug with x and p fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
alsantia@c2r5s1.42lisboa.com committed Apr 25, 2021
1 parent afa4586 commit 2ba2572
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions includes/ft_printf.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: alsantia <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/13 15:11:01 by alsantia #+# #+# */
/* Updated: 2021/04/25 15:38:53 by alsantia ### ########.fr */
/* Updated: 2021/04/25 17:00:51 by alsantia ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -38,7 +38,8 @@ int ft_printf(const char *str, ...);
size_t ft_putchar(char c);
void ft_putnbr(int n, char *res, int is_neg, int mod);
void ft_putnbr_u(unsigned int nb, char *res);
void ft_putnbr_h(unsigned long nb, char *res, char c);
void ft_putnbr_h(unsigned long nb, char *res, char c, int is_pointer);
//void ft_putnbr_h(unsigned int nb, char *res, char c);
size_t ft_putstr(char *s);
size_t ft_putstr_n(char *s, size_t n);
void ft_str_reverse(char *str);
Expand Down
4 changes: 2 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ int main()
// static char a01;

puts("123456789012345678901234567890");
printf("%p %p|\n", ULONG_MAX, -ULONG_MAX);
ft_printf("%p %p|\n", ULONG_MAX, -ULONG_MAX);
printf("%*.*x|\n", 10, 21, -10);
ft_printf("%*.*x|\n", 10, 21, -10);
//x 392
return 0;
}
7 changes: 5 additions & 2 deletions srcs/ft_putnbr_h.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: alsantia <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/04/15 18:08:10 by alsantia #+# #+# */
/* Updated: 2021/04/15 18:10:13 by alsantia ### ########.fr */
/* Updated: 2021/04/25 17:00:12 by alsantia ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -19,11 +19,14 @@ static char to_upper_h(char c)
return (c);
}

void ft_putnbr_h(unsigned long n, char *res, char c)
void ft_putnbr_h(unsigned long n, char *res, char c, int is_pointer)
//void ft_putnbr_h(unsigned int n, char *res, char c)
{
char *hex;
char *p;

if (!is_pointer)
n = (unsigned int)n;
hex = ft_strdup("0123456789abcdef");
p = res;
if (n == 0)
Expand Down
4 changes: 2 additions & 2 deletions srcs/ft_treat_type_p.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: alsantia <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/04/18 16:34:28 by alsantia #+# #+# */
/* Updated: 2021/04/18 16:35:42 by alsantia ### ########.fr */
/* Updated: 2021/04/25 17:00:12 by alsantia ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -31,7 +31,7 @@ size_t ft_treat_type_p(t_flags *flag, va_list ap, char *buf, size_t count)
flag->minus = 1;
flag->width *= -1;
}
ft_putnbr_h(va_arg(ap, long), buf, 'x');
ft_putnbr_h(va_arg(ap, long), buf, 'x', 1);
len = ft_strlen(buf) + 2;
count += len;
if (flag->minus)
Expand Down
5 changes: 3 additions & 2 deletions srcs/ft_treat_type_x.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: alsantia <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/04/25 15:46:54 by alsantia #+# #+# */
/* Updated: 2021/04/25 15:48:19 by alsantia ### ########.fr */
/* Updated: 2021/04/25 17:00:11 by alsantia ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -63,7 +63,8 @@ size_t ft_treat_type_x(t_flags *flag, va_list ap, char *buf)

count = 0;
ft_check_flag(flag, ap);
ft_putnbr_h(va_arg(ap, unsigned long), buf, 'x');
//ft_putnbr_h(va_arg(ap, unsigned long), buf, 'x');//HERE
ft_putnbr_h(va_arg(ap, int), buf, 'x', 0);
if (*buf == '0' && flag->precision == 0)
return (ft_pad(flag, ft_strlen(buf) - 1));
if (!flag->minus && !flag->zero)
Expand Down

0 comments on commit 2ba2572

Please sign in to comment.