Projet de l'école 42 : Printf
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

57 lines
1.1 KiB

#include "ft_printf.h"
char *ft_strnew(int n, char c)
{
char *str = NULL;
if (n < 0)
return (NULL);
str = malloc(n + 1);
if (!str)
return (NULL);
str[n] = '\0';
while (--n >= 0)
str[n] = c;
return (str);
}
char *ft_zero_fill(char *nbr, char c, t_opts *opts)
{
int len;
char *fill = NULL;
if (opts->zero)
len = opts->width - ft_strlen(nbr);
else if (opts->dot)
len = opts->precision - ft_strlen(nbr);
else
return (NULL);
if (len < 0 || (opts->zero && len == 0))
return (NULL);
if ((nbr[0] == '-' || nbr[0] == '+' || nbr[0] == ' ') && opts->dot)
fill = ft_strnew(len + 1, c);
else
fill = ft_strnew(len , c);
if (nbr[0] == '-' || nbr[0] == '+' || nbr[0] == ' ')
{
fill[0] = nbr[0];
nbr[0] = '0';
}
return (fill);
}
char *ft_append(char *s1, char *s2) {
char *ret = NULL;
if (!s1)
return (s2);
if (!s2)
return (s1);
ret = ft_strjoin(s1, s2);
free(s1);
free(s2);
return (ret);
}