42-archive/libftasm/src/ft_printf/lib_pad.c
2016-09-25 02:29:37 +02:00

39 lines
673 B
C

#include "ftprintf.h"
void ft_pad_right(char *str, t_fmt *fmt)
{
ft_pad_sharp(str, fmt);
while ((int)ft_strlen(str) < fmt->width)
ft_strcat(str, " ");
}
void ft_pad_left(char *str, t_fmt *fmt)
{
char buf[100];
char sign;
sign = '\0';
if (str[0] == '-' || str[0] == '+' || str[0] == ' ')
{
sign = str[0];
str++;
}
if (ft_strchr(fmt->flags, '0'))
{
while ((int)ft_strlen(str) < fmt->width - (sign ? 1 : 0))
{
ft_strcpy(buf, "0");
ft_strcat(buf, str);
ft_strcpy(str, buf);
}
}
if (sign)
str--;
ft_pad_sharp(str, fmt);
while ((int)ft_strlen(str) < fmt->width)
{
ft_strcpy(buf, " ");
ft_strcat(buf, str);
ft_strcpy(str, buf);
}
}