aboutsummaryrefslogtreecommitdiff
path: root/convert_char.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-10-30 18:07:21 +0100
committerCharles <sircharlesaze@gmail.com>2019-10-30 18:07:21 +0100
commit22f334a19cabebf10727d7894102946ba23d0e37 (patch)
treefd323ff0dbb8fc06a00c8c26dfc6fbd3b5ae0910 /convert_char.c
parent001786c8ec464b1ae3e6321acfd984227cb1bbee (diff)
downloadft_printf-22f334a19cabebf10727d7894102946ba23d0e37.tar.gz
ft_printf-22f334a19cabebf10727d7894102946ba23d0e37.tar.bz2
ft_printf-22f334a19cabebf10727d7894102946ba23d0e37.zip
Fixed %d segfault, merge hex_* in hex, fixed c = 0
Diffstat (limited to 'convert_char.c')
-rw-r--r--convert_char.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/convert_char.c b/convert_char.c
index ee30a2c..d6c3422 100644
--- a/convert_char.c
+++ b/convert_char.c
@@ -1,4 +1,5 @@
#include <stdarg.h>
+#include <stdlib.h>
#include "header.h"
char *convert_char(va_list ap, t_pformat *pformat)
@@ -8,6 +9,33 @@ char *convert_char(va_list ap, t_pformat *pformat)
return (NULL);
str[0] = va_arg(ap, int);
str[1] = '\0';
- str = handle_padding(pformat, str);
+
+ /* str = handle_padding(pformat, str); */
+ pformat->size = 1;//ft_strlen(str);
+ /* return (str); */
+ char *tmp;
+ int i;
+ if (1 >= pformat->min_width)
+ return (str);
+ if ((tmp = (char*)malloc(sizeof(char) * (pformat->min_width + 1))) == NULL)
+ return (NULL);
+ if (pformat->flags & FLAG_LEFT_ADJUSTED)
+ {
+ i = 1;
+ ft_memcpy(tmp, str, 2);
+ while (i < pformat->min_width)
+ tmp[i++] = ' ';
+ tmp[i] = 0;
+ }
+ else
+ {
+ i = 0;
+ while (i <= pformat->min_width - 1)
+ tmp[i++] = pformat->flags & FLAG_ZERO_PADDING ? '0' : ' ';
+ ft_memcpy(tmp + i - 1, str, 2);
+ }
+ free(str);
+ pformat->size = pformat->min_width;
+ return (tmp);
return (str);
}