feat: added ft_putnbr and ft-putunbr

This commit is contained in:
Zoëy Noort 2025-05-11 19:23:16 +02:00
parent 9bf197acbd
commit 2a9b042122
2 changed files with 35 additions and 0 deletions

21
srcs/ft_putnbr.c Normal file
View file

@ -0,0 +1,21 @@
#include "libft.h"
#include <unistd.h>
int ft_putnbr(int n)
{
int count = 0;
char c;
if (n == -2147483648)
return write(1, "-2147483648", 11);
if (n < 0)
{
count += ft_putchar('-');
n = -n;
}
if (n >= 10)
count += ft_putnbr(n / 10);
c = '0' + (n % 10);
count += ft_putchar(c);
return count;
}