Repaired Makefile to properly build the resulting library from libft.a.
authorLukas Jiriste <ljiriste@student.42prague.com>
Fri, 15 Sep 2023 15:58:45 +0000 (17:58 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Fri, 15 Sep 2023 15:58:45 +0000 (17:58 +0200)
Also patched leak that was happening in formatting.

Makefile
conversion.c
formatting.c
ft_printf.h

index dcb449f3d7a6a1089abe3b0a91b43bce7a4a2b28..4c8d68d8e4dd92b4aaf84894aecf6d8fe5554359 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -8,13 +8,14 @@ INCLUDE = $(addprefix -I, . ./Libft)
 SRCDIR = .
 # SOURCES = $(addprefix $(SRCDIR)/, ft_putchar.c ft_putstr.c ft_strcmp.c ft_strlen.c ft_swap.c)
 SOURCES = $(shell find $(SRCDIR) -maxdepth 1 -name "*.c")
-OBJECTS = $(SOURCES:.c=.o) libft.a
+OBJECTS = $(SOURCES:.c=.o)
 
 NAME = libftprintf.a
 
 all : $(NAME)
 
-$(NAME) : $(OBJECTS)
+$(NAME) : $(OBJECTS) libft.a
+       mv libft.a $(NAME)
        $(AR) rcs $(NAME) $(OBJECTS)
 
 libft.a :
index 9423cb3d4bd07b6baf826998b04634a212f0c385..d476bbd1e0a55e78dfc14b3abbd7c74eca1f421d 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2023/09/05 11:30:56 by ljiriste          #+#    #+#             */
-/*   Updated: 2023/09/11 12:41:51 by ljiriste         ###   ########.fr       */
+/*   Updated: 2023/09/15 15:32:41 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -98,7 +98,7 @@ int   handle_conversion(const char **format, va_list *args)
                return (1);
        }
        temp = base_str_constr(conv.type, args);
-       to_print = formatting(temp, conv);
+       to_print = formatting(&temp, conv);
        free(temp);
        if (!valid_toprint(to_print))
                return (-1);
index 1b66f0be66c9582efba24165e0e18666963e6174..13569375761a2807924a39f0ab857c8a0c9cfefb 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2023/09/05 11:28:21 by ljiriste          #+#    #+#             */
-/*   Updated: 2023/09/11 12:42:41 by ljiriste         ###   ########.fr       */
+/*   Updated: 2023/09/15 15:33:50 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -84,19 +84,19 @@ static void init_printed(t_to_print *tp)
        return ;
 }
 
-t_to_print     formatting(char *str, t_conv conv)
+t_to_print     formatting(char **str, t_conv conv)
 {
        t_to_print      res;
 
-       if ((conv.type == 'p' && ft_strncmp(str, "0", 2) == 0))
+       if ((conv.type == 'p' && ft_strncmp(*str, "0", 2) == 0))
        {
-               free (str);
-               str = ft_strdup("(nil)");
+               free (*str);
+               *str = ft_strdup("(nil)");
        }
-       else if (conv.type == 's' && str == NULL)
-               str = ft_strdup("(null)");
+       else if (conv.type == 's' && *str == NULL)
+               *str = ft_strdup("(null)");
        init_printed(&res);
-       create_main(str, &res, conv);
+       create_main(*str, &res, conv);
        create_alt(&res, conv);
        create_padding(&res, conv);
        return (res);
index 931ae1a4a0430db0968956d848abd3ce8c2a1b5e..bcfe53e0b71e40d5f1de275ef51c349662ed1196 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2023/09/05 12:00:16 by ljiriste          #+#    #+#             */
-/*   Updated: 2023/09/05 12:27:18 by ljiriste         ###   ########.fr       */
+/*   Updated: 2023/09/15 15:34:21 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -44,7 +44,7 @@ typedef struct s_to_print
 
 int                    ft_printf(const char *format, ...);
 int                    handle_conversion(const char **format, va_list *args);
-t_to_print     formatting(char *str, t_conv conv);
+t_to_print     formatting(char **str, t_conv conv);
 t_conv         parse_format(const char **format, va_list *args);
 void           create_padding(t_to_print *tp, t_conv conv);