diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-11-06 00:02:56 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-11-06 00:02:56 +0100 |
| commit | dafee6410a4ecd7400a83adf84ded3621f30a365 (patch) | |
| tree | 401c4169f4c2bf849d33a6a0201ab47d0f0f7782 /convert_char.c | |
| parent | e6d8f543af4c1a45f30495b90a3912b1c75f2be7 (diff) | |
| download | ft_printf-dafee6410a4ecd7400a83adf84ded3621f30a365.tar.gz ft_printf-dafee6410a4ecd7400a83adf84ded3621f30a365.tar.bz2 ft_printf-dafee6410a4ecd7400a83adf84ded3621f30a365.zip | |
Refactored parsing to handle alone '%'
- renamed a few variables
- added join_free* to libft
- normed everything but ft_printf.c
Diffstat (limited to 'convert_char.c')
| -rw-r--r-- | convert_char.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/convert_char.c b/convert_char.c index c838974..8e51804 100644 --- a/convert_char.c +++ b/convert_char.c @@ -6,41 +6,38 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/30 23:22:29 by cacharle #+# #+# */ -/* Updated: 2019/11/03 20:13:44 by cacharle ### ########.fr */ +/* Updated: 2019/11/05 23:44:42 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ -#include <stdarg.h> -#include <stdlib.h> -#include "libft.h" #include "header.h" -static char *handle_padding_char(t_pformat *pformat, char *str) +static char *handle_width_char(t_pformat *pformat, char *str) { char *tmp; int i; pformat->size = 1; - if (1 >= pformat->min_width) + if (1 >= pformat->width) return (str); - if ((tmp = (char*)malloc(sizeof(char) * (pformat->min_width + 1))) == NULL) + if ((tmp = (char*)malloc(sizeof(char) * (pformat->width + 1))) == NULL) return (NULL); - if (pformat->flags & FLAG_LEFT_ADJUSTED) + if (pformat->flags & FLAG_MINUS) { ft_memcpy(tmp, str, (i = 1) + 1); - while (i < pformat->min_width) + while (i < pformat->width) tmp[i++] = ' '; tmp[i] = 0; } else { i = 0; - while (i <= pformat->min_width - 1) - tmp[i++] = pformat->flags & FLAG_ZERO_PADDING ? '0' : ' '; + while (i <= pformat->width - 1) + tmp[i++] = pformat->flags & FLAG_ZERO ? '0' : ' '; ft_memcpy(tmp + i - 1, str, 2); } free(str); - pformat->size = pformat->min_width; + pformat->size = pformat->width; return (tmp); } @@ -52,5 +49,5 @@ char *convert_char(va_list ap, t_pformat *pformat) return (NULL); str[0] = va_arg(ap, int); str[1] = '\0'; - return (handle_padding_char(pformat, str)); + return (handle_width_char(pformat, str)); } |
