diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-10-28 04:15:16 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-10-28 04:15:16 +0100 |
| commit | f6ee1462e26d723cf5d53157eadaff2804d18c3a (patch) | |
| tree | 366ba00a09afe4b7d21c55ee25fd98030b2cd5a5 /ft_printf.c | |
| parent | feb71e200972bb78fe86130629ef040ef80811a7 (diff) | |
| download | ft_printf-f6ee1462e26d723cf5d53157eadaff2804d18c3a.tar.gz ft_printf-f6ee1462e26d723cf5d53157eadaff2804d18c3a.tar.bz2 ft_printf-f6ee1462e26d723cf5d53157eadaff2804d18c3a.zip | |
reformed pformat struct, rename t_flist
Diffstat (limited to 'ft_printf.c')
| -rw-r--r-- | ft_printf.c | 74 |
1 files changed, 31 insertions, 43 deletions
diff --git a/ft_printf.c b/ft_printf.c index 27b4734..ce7f15c 100644 --- a/ft_printf.c +++ b/ft_printf.c @@ -5,47 +5,35 @@ int ft_printf(const char *format, ...) { - int print_len; - /* va_list ap; */ - /* #<{(| va_list ap_start; |)}># */ - /* #<{(| int ap_index; |)}># */ - /* t_list *format_list; */ - /* char *str; */ - /* */ - /* if ((format_list = parse(format)) == NULL) */ - /* return (-1); */ - /* #<{(| ap_index = 0; |)}># */ - /* va_start(ap, format); */ - /* */ - /* #<{(| va_copy(ap_start, ap); |)}># */ - /* print_len = -1; */ - /* while (format[++print_len]) */ - /* { */ - /* if (format[print_len] == '%') */ - /* { */ - /* if (format_list->data->ap_index != -1) */ - /* { */ - /* ap_index = format_list->data->ap_index; */ - /* } */ - /* else */ - /* ap_index++; */ - /* printf("\n%d\n", format_list->data->left_adjusted); */ - /* printf("\n%d\n", format_list->data->precision); */ - /* printf("\n%d\n", format_list->data->precision_wildcard); */ - /* printf("\n%d\n", format_list->data->min_field_width); */ - /* if ((str = convert_to_str(format_list->content, ap)) == NULL) */ - /* return (-1); */ - /* ft_putstr(str); */ - /* free(str); */ - /* */ - /* print_len += format_list->content->len; */ - /* list_pop_front(&format_list); */ - /* } */ - /* else */ - /* write(STDOUT_FILENO, format + print_len, 1); */ - /* } */ - /* va_end(ap); */ - (void)format; - print_len = 0; - return (print_len); + va_list ap; + t_flist *format_list; + char *str; + int print_len; + int i; + + if ((format_list = parse(format)) == NULL) + return (-1); + va_start(ap, format); + print_len = 0; + i = -1; + while (format[++i]) + { + if (format[i] == '%') + { + if ((str = convert_to_str(format_list->content, ap)) == NULL) + { + list_destroy(&format_list); + return (-1); + } + ft_putstr(str); + print_len += ft_strlen(str); + free(str); + i += format_list->content->len; + list_pop_front(&format_list); + } + else + write(STDOUT_FILENO, format + i, 1); + } + va_end(ap); + return (print_len + i); } |
