diff --git a/ft_printf.c b/ft_printf.c index f03ef69..8425c99 100644 --- a/ft_printf.c +++ b/ft_printf.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/17 16:48:37 by adjoly #+# #+# */ -/* Updated: 2023/11/22 13:01:29 by adjoly ### ########.fr */ +/* Updated: 2023/11/22 14:01:50 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,7 @@ int ft_putaddr(void *ptr) if (ptr == NULL) return (write(1, "(nil)", 5)); write(1, "0x", 2); - r = ft_putnbrbase((long unsigned int)ptr, "0123456789abcdef"); + r = ft_putnbrbase_p((long unsigned int)ptr, "0123456789abcdef"); return (2 + r); } diff --git a/ft_printf.h b/ft_printf.h index f21ff19..fa3cdb7 100644 --- a/ft_printf.h +++ b/ft_printf.h @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/17 16:50:36 by adjoly #+# #+# */ -/* Updated: 2023/11/22 11:24:27 by adjoly ### ########.fr */ +/* Updated: 2023/11/22 14:00:38 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,7 +23,9 @@ int ft_putnbrulong(unsigned int n); int ft_putaddr(void *ptr); int ft_putstr(char *s); -int ft_putnbrbase(unsigned long int n, char *base); + +int ft_putnbrbase_p(unsigned long int n, char *base); +int ft_putnbrbase(unsigned int n, char *base); int ft_putchar(char c); int ft_putnbr(int n); size_t ft_strlen(const char *s); diff --git a/ft_printf.o b/ft_printf.o new file mode 100644 index 0000000..f899e54 Binary files /dev/null and b/ft_printf.o differ diff --git a/ft_putchar.o b/ft_putchar.o new file mode 100644 index 0000000..bcef31d Binary files /dev/null and b/ft_putchar.o differ diff --git a/ft_putnbr.o b/ft_putnbr.o new file mode 100644 index 0000000..393d144 Binary files /dev/null and b/ft_putnbr.o differ diff --git a/ft_putnbrbase.c b/ft_putnbrbase.c index 7e3073a..1866219 100644 --- a/ft_putnbrbase.c +++ b/ft_putnbrbase.c @@ -6,16 +6,16 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/18 10:57:44 by adjoly #+# #+# */ -/* Updated: 2023/11/22 13:21:55 by adjoly ### ########.fr */ +/* Updated: 2023/11/22 14:02:37 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_printf.h" -int ft_putnbrbase(unsigned long int n, char *base) +int ft_putnbrbase(unsigned int n, char *base) { - unsigned long int base_len; - int len; + unsigned int base_len; + int len; len = 0; base_len = (int)ft_strlen(base); @@ -28,3 +28,20 @@ int ft_putnbrbase(unsigned long int n, char *base) } return (len); } + +int ft_putnbrbase_p(unsigned long int n, char *base) +{ + unsigned long int base_len; + int len; + + len = 0; + base_len = (int)ft_strlen(base); + if (n < base_len) + len += write(1, &base[n % base_len], 1); + else + { + len += ft_putnbrbase_p(n / base_len, base); + len += write(1, &base[n % base_len], 1); + } + return (len); +} diff --git a/ft_putnbrbase.o b/ft_putnbrbase.o new file mode 100644 index 0000000..bbd7831 Binary files /dev/null and b/ft_putnbrbase.o differ diff --git a/ft_putstr.o b/ft_putstr.o new file mode 100644 index 0000000..ecfa1a3 Binary files /dev/null and b/ft_putstr.o differ diff --git a/ft_strlen.o b/ft_strlen.o new file mode 100644 index 0000000..6b9b640 Binary files /dev/null and b/ft_strlen.o differ diff --git a/libftprintf.a b/libftprintf.a new file mode 100644 index 0000000..9b04894 Binary files /dev/null and b/libftprintf.a differ