aboutsummaryrefslogtreecommitdiff
path: root/ft_printf.c
diff options
context:
space:
mode:
Diffstat (limited to 'ft_printf.c')
-rw-r--r--ft_printf.c49
1 files changed, 38 insertions, 11 deletions
diff --git a/ft_printf.c b/ft_printf.c
index c51cc22..cf5e020 100644
--- a/ft_printf.c
+++ b/ft_printf.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/29 00:15:28 by cacharle #+# #+# */
-/* Updated: 2019/10/30 02:01:25 by cacharle ### ########.fr */
+/* Updated: 2019/10/30 17:10:32 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,7 +19,7 @@
int ft_printf(const char *format, ...)
{
va_list ap;
- t_flist *format_list;
+ t_flist *flist;
char *str;
int print_len;
int i;
@@ -27,7 +27,7 @@ int ft_printf(const char *format, ...)
if (format == NULL)
return (-1);
str = ft_strdup(format);
- if (!parse(str, &format_list))
+ if (!parse(str, &flist))
return (-1);
free(str);
va_start(ap, format);
@@ -40,19 +40,46 @@ int ft_printf(const char *format, ...)
write(STDOUT_FILENO, format + i, 1);
continue ;
}
- str = convert(format_list->content, ap);
+ str = convert(flist->content, ap);
if (str == NULL)
{
- list_destroy(&format_list);
+ list_destroy(&flist);
return (-1);
}
- ft_putstr(str);
- print_len += ft_strlen(str);
- free(str);
- i += format_list->content->len;
- list_pop_front(&format_list);
+ if (flist->content->type == 'c')
+ {
+ write(1, str, flist->content->size);
+ /* printf("\n%d\n", flist->content->size); */
+ print_len++;
+ free(str);
+ }
+ else
+ {
+ ft_putstr(str);
+ print_len += ft_strlen(str);
+ free(str);
+ }
+ i += flist->content->fmt_len;
+ list_pop_front(&flist);
}
- list_destroy(&format_list);
+ list_destroy(&flist);
va_end(ap);
return (print_len + i);
}
+
+char *ft_strappend(char *dest, char *src)
+{
+ void *copy;
+
+ if ((copy = (char*)malloc(sizeof(char) * (ft_strlen(dest) + 1))) == NULL)
+ return (NULL);
+ ft_strcpy(copy, dest);
+ free(dest);
+ dest = (char*)malloc(sizeof(char) * (ft_strlen(copy) + ft_strlen(src) + 1));
+ if (dest == NULL)
+ return (NULL);
+ ft_strcpy(dest, copy);
+ free(copy);
+ ft_strcat(dest, src);
+ return (dest);
+}