ft_putnbr.c

This commit is contained in:
Timo Schmidt 2023-03-27 19:51:26 +02:00
parent f7e1cd0b41
commit fb8dc3538b
1 changed files with 60 additions and 0 deletions

60
ex02/ft_putnbr.c Normal file
View File

@ -0,0 +1,60 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 18:57:42 by tischmid #+# #+# */
/* Updated: 2023/03/27 19:50:56 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
#include <limits.h>
#include <unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_putnbr(int nb)
{
if (nb > 9)
{
ft_putnbr(nb / 10);
ft_putchar(nb % 10 + '0');
}
else if (nb == INT_MIN)
{
ft_putnbr(nb / 10);
ft_putnbr(-(nb % 10));
}
else if (nb < 0)
{
ft_putchar('-');
ft_putnbr(-nb);
}
else
ft_putchar(nb % 10 + '0');
}
/* ////
int main(void)
{
ft_putnbr(INT_MIN);
write(1, "\n", 1);
ft_putnbr(-12);
write(1, "\n", 1);
ft_putnbr(-1);
write(1, "\n", 1);
ft_putnbr(0);
write(1, "\n", 1);
ft_putnbr(1);
write(1, "\n", 1);
ft_putnbr(12);
write(1, "\n", 1);
ft_putnbr(INT_MAX);
write(1, "\n", 1);
}
*/ ////