From 1822beefff19891ec462e4766cb58f7cd9f0880d Mon Sep 17 00:00:00 2001 From: Xamora Date: Mon, 21 Nov 2022 20:56:17 +0100 Subject: [PATCH] =?UTF-8?q?Correction=20Makefile=20et=20suppression=20'y'?= =?UTF-8?q?=20inutile=20et=20all=C3=A8gement=20du=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 2 +- ft_printf.c | 8 +++----- ft_printf.h | 2 +- ft_putnbrhex.c | 2 +- ft_putvd.c | 25 +------------------------ 5 files changed, 7 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index 48c320e..3d84efc 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ # # # **************************************************************************** # -SRCS = ft_get_size.c ft_itoa.c ft_power.c ft_printf.c ft_putchar.c ft_putnbr.c \ +SRCS = ft_get_size.c ft_power.c ft_printf.c ft_putchar.c ft_putnbr.c \ ft_putnbrhex.c ft_putnbrhex_upper.c ft_putstr.c ft_putunbr.c ft_putvd.c OBJS = ${SRCS:.c=.o} CC = gcc diff --git a/ft_printf.c b/ft_printf.c index 386b4d2..c2f6be9 100644 --- a/ft_printf.c +++ b/ft_printf.c @@ -65,26 +65,24 @@ int ft_printf(const char *str, ...) { va_list args; int i; - int y; int count; va_start(args, str); - i = -1; - y = 0; + i = 0; count = 0; - while (str[++i]) + while (str[i]) { if (str[i] == '%' && ft_is_format(str[i + 1])) { count += ft_post_character(str[i + 1], args); i++; - y++; } else { ft_putchar(str[i]); count++; } + i++; } va_end(args); return (count); diff --git a/ft_printf.h b/ft_printf.h index f118253..5aeeb07 100644 --- a/ft_printf.h +++ b/ft_printf.h @@ -24,7 +24,7 @@ int ft_power(int nb, int power); int ft_get_size(long long n); int ft_putnbr(int n); int ft_putunbr(unsigned int n); -int ft_putnbrhex(unsigned int v); +int ft_putnbrhex(unsigned long v); int ft_putnbrhex_upper(unsigned int v); int ft_putvd(void *v); diff --git a/ft_putnbrhex.c b/ft_putnbrhex.c index fcc3757..f988acc 100644 --- a/ft_putnbrhex.c +++ b/ft_putnbrhex.c @@ -12,7 +12,7 @@ #include "ft_printf.h" -int ft_putnbrhex(unsigned int v) +int ft_putnbrhex(unsigned long v) { int tmp; int count; diff --git a/ft_putvd.c b/ft_putvd.c index c0075f9..0faf5d3 100644 --- a/ft_putvd.c +++ b/ft_putvd.c @@ -12,29 +12,6 @@ #include "ft_printf.h" -static int ft_putnbrhexull(unsigned long v) -{ - int tmp; - int count; - char hex[100]; - - count = 0; - tmp = 0; - while (v != 0) - { - tmp = v % 16; - if (tmp < 10) - hex[count++] = tmp + 48; - else - hex[count++] = tmp + 87; - v = v / 16; - } - tmp = count - 1; - while (tmp >= 0) - ft_putchar(hex[tmp--]); - return (count); -} - int ft_putvd(void *v) { int count; @@ -45,6 +22,6 @@ int ft_putvd(void *v) u = (unsigned long)v; count = 2; ft_putstr("0x"); - count += ft_putnbrhexull(u); + count += ft_putnbrhex(u); return (count); }