aboutsummaryrefslogtreecommitdiff
path: root/convert_char.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-10-30 23:35:40 +0100
committerCharles <sircharlesaze@gmail.com>2019-10-30 23:35:40 +0100
commitd63d6916249f5b40b81097854d8ca2c9d4d7d071 (patch)
treeb98fe6a060fdb632d00ddf9385f6579a32619f38 /convert_char.c
parent22f334a19cabebf10727d7894102946ba23d0e37 (diff)
downloadft_printf-d63d6916249f5b40b81097854d8ca2c9d4d7d071.tar.gz
ft_printf-d63d6916249f5b40b81097854d8ca2c9d4d7d071.tar.bz2
ft_printf-d63d6916249f5b40b81097854d8ca2c9d4d7d071.zip
Normed converters
Diffstat (limited to 'convert_char.c')
-rw-r--r--convert_char.c43
1 files changed, 29 insertions, 14 deletions
diff --git a/convert_char.c b/convert_char.c
index d6c3422..083a6e9 100644
--- a/convert_char.c
+++ b/convert_char.c
@@ -1,28 +1,33 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* convert_char.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/10/30 23:22:29 by cacharle #+# #+# */
+/* Updated: 2019/10/30 23:33:44 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#include <stdarg.h>
#include <stdlib.h>
+#include "libft.h"
#include "header.h"
-char *convert_char(va_list ap, t_pformat *pformat)
+static char *handle_padding_char(t_pformat *pformat, char *str)
{
- char *str = ft_strnew(2);
- if (str == NULL)
- return (NULL);
- str[0] = va_arg(ap, int);
- str[1] = '\0';
+ char *tmp;
+ int i;
- /* str = handle_padding(pformat, str); */
- pformat->size = 1;//ft_strlen(str);
- /* return (str); */
- char *tmp;
- int i;
+ pformat->size = 1;
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);
+ ft_memcpy(tmp, str, (i = 1) + 1);
while (i < pformat->min_width)
tmp[i++] = ' ';
tmp[i] = 0;
@@ -37,5 +42,15 @@ char *convert_char(va_list ap, t_pformat *pformat)
free(str);
pformat->size = pformat->min_width;
return (tmp);
- return (str);
+}
+
+char *convert_char(va_list ap, t_pformat *pformat)
+{
+ char *str;
+
+ if ((str = ft_strnew(2)) == NULL)
+ return (NULL);
+ str[0] = va_arg(ap, int);
+ str[1] = '\0';
+ return (handle_padding_char(pformat, str));
}