aboutsummaryrefslogtreecommitdiff
path: root/printer.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 /printer.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 'printer.c')
-rw-r--r--printer.c37
1 files changed, 12 insertions, 25 deletions
diff --git a/printer.c b/printer.c
index a4da1a1..6ee88ff 100644
--- a/printer.c
+++ b/printer.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/28 23:19:24 by cacharle #+# #+# */
-/* Updated: 2019/10/30 04:13:18 by cacharle ### ########.fr */
+/* Updated: 2019/10/30 18:04:06 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -52,9 +52,9 @@ char *convert_type(va_list ap, t_pformat *pformat)
if (pformat->type == 'u')
return (convert_uint(ap, pformat));
if (pformat->type == 'x')
- return (convert_hex_low(ap, pformat));
+ return (convert_hex(ap, pformat));
if (pformat->type == 'X')
- return (convert_hex_up(ap, pformat));
+ return (convert_hex(ap, pformat));
if (pformat->type == '%')
return (convert_percent(ap, pformat));
return (NULL);
@@ -116,26 +116,13 @@ char *handle_precision(t_pformat *pformat, char *str)
len = ft_strlen(str);
if (pformat->precision == 0 && str[0] == '0')
return (ft_strdup(""));
- else if (IN_STR("diuxXp", pformat->type) && len < pformat->precision)
- {
- if ((tmp = (char*)malloc(sizeof(char) * (pformat->precision + 1))) == NULL)
- return (NULL);
- if (IN_STR("+-", str[0]))
- {
- tmp[0] = str[0];
- len--;
- ft_strcpy(tmp + pformat->precision - len + 1, str + 1);
- while (pformat->precision-- > len)
- tmp[pformat->precision - len + 1] = '0';
- ft_strcpy(str, tmp);
- free(tmp);
- return (str);
- }
- ft_strcpy(tmp + pformat->precision - len, str);
- while (pformat->precision-- > len)
- tmp[pformat->precision - len] = '0';
- ft_strcpy(str, tmp);
- free(tmp);
- }
- return (str);
+ if (!IN_STR("diuxXp", pformat->type) || len >= pformat->precision)
+ return (str);
+ if ((tmp = (char*)malloc(sizeof(char) * (pformat->precision + 1))) == NULL)
+ return (NULL);
+ ft_strcpy(tmp + pformat->precision - len, str);
+ while (pformat->precision-- > len)
+ tmp[pformat->precision - len] = '0';
+ free(str);
+ return (tmp);
}