Skip to content

Commit

Permalink
012 [Fixed] hex format repaired working properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
salecler committed Aug 25, 2022
1 parent 0082747 commit 0d62247
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# By: salecler <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/08/24 16:23:21 by salecler #+# #+# #
# Updated: 2022/08/24 17:35:57 by salecler ### ########.fr #
# Updated: 2022/08/25 11:30:49 by salecler ### ########.fr #
# #
# **************************************************************************** #

Expand Down
4 changes: 2 additions & 2 deletions include/ft_printf.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: salecler <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/24 11:56:09 by salecler #+# #+# */
/* Updated: 2022/08/24 17:54:35 by salecler ### ########.fr */
/* Updated: 2022/08/25 11:28:54 by salecler ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -27,6 +27,6 @@ int ft_putstr(char *str);
//Formats archive
int ft_putnbr(int n);
int ft_putnbr_base(unsigned long n, char *base);
int ft_puthex(int n, char *base);
int ft_puthex(size_t n, char *base);
int ft_putptr(void *n);
#endif
35 changes: 13 additions & 22 deletions src/ft_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: salecler <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/24 11:55:55 by salecler #+# #+# */
/* Updated: 2022/08/24 17:47:05 by salecler ### ########.fr */
/* Updated: 2022/08/25 11:29:38 by salecler ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -43,7 +43,7 @@ int ft_putnbr_base(unsigned long n, char *base)

nbr = (unsigned int)n;
len = 0;
if (nbr > 16)
if (nbr >= 16)
{
ft_putnbr_base(nbr / 16, base);
nbr = nbr % 16;
Expand All @@ -53,41 +53,32 @@ int ft_putnbr_base(unsigned long n, char *base)
return (len);
}

int ft_puthex(int n, char *base)
int ft_puthex(size_t n, char *base)
{
int len;
int nbr;
static int len;

len = 0;
nbr = n;
if (nbr < 0)
if (n >= 16)
{
write(1, "-", 1);
nbr *= -1;
}
if (nbr > 16)
{
ft_puthex(nbr / 16, base);
nbr = nbr % 16;
ft_puthex(n / 16, base);
n = n % 16;
}
len++;
ft_putchar(nbr + '0');
if (n < 0)
len++;
ft_putchar(base[n]);
return (len);
}

int ft_putptr(void *n)
{
int len;
int nbr;
char *base;
int len;
size_t nbr;
char *base;

len = 0;
nbr = (int)n;
nbr = (size_t)n;
base = "0123456789abcdef";
write(1, "0x", 2);
len += 2;
len += ft_putnbr_base(nbr, base);
len += ft_puthex(nbr, base);
return (len);
}
3 changes: 2 additions & 1 deletion src/ft_printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
/* By: salecler <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/22 18:32:02 by salecler #+# #+# */
/* Updated: 2022/08/24 17:48:56 by salecler ### ########.fr */
/* Updated: 2022/08/25 11:31:23 by salecler ### ########.fr */
/* */
/* ************************************************************************** */

#include "../include/ft_printf.h"
#include <stdio.h>

int ft_printf(const char *str, ...)
{
Expand Down

0 comments on commit 0d62247

Please sign in to comment.