diff --git a/Makefile b/Makefile index 617f702..977714a 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: adjoly +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/17 12:35:27 by adjoly #+# #+# # -# Updated: 2023/11/17 14:38:41 by adjoly ### ########.fr # +# Updated: 2023/11/17 19:59:14 by adjoly ### ########.fr # # # # **************************************************************************** # @@ -14,13 +14,14 @@ NAME = libftprintf.a CC = cc -SRCS = \ +SRCS = ft_printf.c\ + OBJS = $(SRCS:.c=.o) FLAGS = -Werror -Wall -Wextra -HEADER = libftprintf.h +HEADER = libftprintf.h \ $(NAME): $(OBJS) ar -rcs $(NAME) $(OBJS) diff --git a/ft_printf.c b/ft_printf.c index fc59535..a9db5be 100644 --- a/ft_printf.c +++ b/ft_printf.c @@ -6,17 +6,39 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/17 16:48:37 by adjoly #+# #+# */ -/* Updated: 2023/11/17 17:32:54 by adjoly ### ########.fr */ +/* Updated: 2023/11/17 20:03:48 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ +#include "libft/libft.h" #include "libftprintf.h" #include int ft_printf(const char *format, ...) { - va_list args; + char *result; + int i; + int j; + va_list args; va_start(args, format); - + while (format[i]) + { + if (format[i] == '%') + { + i++; + if (format[i] == '%') + ft_putchar_fd('%', 1); + else if (format[i] == 's') + ft_putstr_fd(va_arg(args, char *), 1); + else if (format[i] == 'c') + ft_putchar_fd(va_arg(args, char *)[0], 1); + else if (format[i] == 'i' || format[i] == 'd') + ft_putnbr_fd(va_arg(args, int), 1); + } + else + ft_putchar_fd(format[i], i); + i++; + } + return (ft_strlen(result)); } diff --git a/libft b/libft new file mode 160000 index 0000000..42f67cc --- /dev/null +++ b/libft @@ -0,0 +1 @@ +Subproject commit 42f67cc750874f0d60c8cdd612c86cf6259fa0c3 diff --git a/libftprintf.h b/libftprintf.h index a0834b7..1302174 100644 --- a/libftprintf.h +++ b/libftprintf.h @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/17 16:50:36 by adjoly #+# #+# */ -/* Updated: 2023/11/17 16:57:31 by adjoly ### ########.fr */ +/* Updated: 2023/11/17 19:48:34 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,7 @@ # include # include +# include "libft/libft.h" int ft_printf(const char *format, ...);