added functions to print strings and numbers with padding of choice

This commit is contained in:
Tanguy MAZE 2018-07-31 16:34:04 +02:00
parent f88ff8a600
commit 8107a8aaf3
2 changed files with 48 additions and 0 deletions

24
ft_putnbrpad.c Normal file
View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbrpad.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/07/31 13:51:17 by tmaze #+# #+# */
/* Updated: 2018/07/31 14:04:43 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbrpad(int nbr, size_t size, char pad, char align)
{
if (align == 'd')
while (size-- != 0)
ft_putchar(pad);
ft_putnbr(nbr);
if (align == 'g')
while (size-- != 0)
ft_putchar(pad);
}

24
ft_putstrpad.c Normal file
View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstrpad.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/07/31 13:36:56 by tmaze #+# #+# */
/* Updated: 2018/07/31 14:05:41 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putstrpad(char *str, size_t size, char pad, char align)
{
if (align == 'd')
while (size-- != 0)
ft_putchar(pad);
ft_putstr(str);
if (align == 'g')
while (size-- != 0)
ft_putchar(pad);
}