64 lines
1.4 KiB
C
64 lines
1.4 KiB
C
|
/* ************************************************************************** */
|
||
|
/* */
|
||
|
/* ::: :::::::: */
|
||
|
/* ft_printf_utils.c :+: :+: :+: */
|
||
|
/* +:+ +:+ +:+ */
|
||
|
/* By: madumerg <madumerg@student.42angouleme. +#+ +:+ +#+ */
|
||
|
/* +#+#+#+#+#+ +#+ */
|
||
|
/* Created: 2023/11/26 15:52:39 by madumerg #+# #+# */
|
||
|
/* Updated: 2024/02/02 14:25:22 by madumerg ### ########.fr */
|
||
|
/* */
|
||
|
/* ************************************************************************** */
|
||
|
|
||
|
#include "ft_printf.h"
|
||
|
|
||
|
int ft_putchar(char c)
|
||
|
{
|
||
|
write(1, &c, 1);
|
||
|
return (1);
|
||
|
}
|
||
|
|
||
|
int ft_putnbr(int n)
|
||
|
{
|
||
|
int i;
|
||
|
|
||
|
i = 0;
|
||
|
if (n == -2147483648)
|
||
|
{
|
||
|
i += ft_putchar('-');
|
||
|
i += ft_putchar('2');
|
||
|
n = 147483648;
|
||
|
}
|
||
|
if (n < 0)
|
||
|
{
|
||
|
i += ft_putchar('-');
|
||
|
n *= -1;
|
||
|
}
|
||
|
if (n < 10)
|
||
|
{
|
||
|
i += ft_putchar(n + '0');
|
||
|
return (i);
|
||
|
}
|
||
|
else if (n >= 10)
|
||
|
{
|
||
|
i += ft_putnbr(n / 10);
|
||
|
i += ft_putnbr(n % 10);
|
||
|
}
|
||
|
return (i);
|
||
|
}
|
||
|
|
||
|
int ft_putstr(char *str)
|
||
|
{
|
||
|
int i;
|
||
|
|
||
|
i = 0;
|
||
|
if (!str)
|
||
|
return (ft_putstr("(null)"));
|
||
|
while (str[i] != '\0')
|
||
|
{
|
||
|
write(1, &str[i], 1);
|
||
|
i++;
|
||
|
}
|
||
|
return (i);
|
||
|
}
|