42_cub3d/Libft/ft_put.c
2024-10-09 03:35:09 +02:00

75 lines
1.8 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_put.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/13 10:26:43 by grobledo #+# #+# */
/* Updated: 2023/04/13 10:26:45 by grobledo ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_putcharf(char c, int count)
{
write(1, &c, 1);
count++;
return (count);
}
int ft_putnbrf(int n, int count)
{
if (n == -2147483648)
{
(write(1, "-2147483648", 11));
count += 11;
return (count);
}
if (n < 0)
{
count = ft_putcharf('-', count);
n *= -1;
count = ft_putnbrf(n, count);
}
else if (n >= 10)
{
count = ft_putnbrf(n / 10, count);
count = ft_putnbrf(n % 10, count);
}
else
{
count = ft_putcharf(n + '0', count);
}
return (count);
}
int ft_putnbrposf(unsigned int n, int count)
{
if (n >= 10)
{
count = ft_putnbrposf(n / 10, count);
count = ft_putnbrposf(n % 10, count);
}
else
{
count = ft_putcharf(n + '0', count);
}
return (count);
}
int ft_putstrf(char *s, int count)
{
int i;
if (!s)
return (ft_putstrf("(null)", count));
i = 0;
while (s[i])
{
write(1, &s[i], 1);
i++;
count++;
}
return (count);
}