mirror of
https://github.com/Ladebeze66/Piscine42.git
synced 2026-11-09 13:17:16 +01:00
Piscine42
This commit is contained in:
40
C04/ex02/ft_putnbr.c
Executable file
40
C04/ex02/ft_putnbr.c
Executable file
@@ -0,0 +1,40 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/11 14:02:07 by fgras-ca #+# #+# */
|
||||
/* Updated: 2022/12/11 17:23:13 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}
|
||||
|
||||
void ft_putnbr(int nb)
|
||||
{
|
||||
if (nb == -2147483648)
|
||||
{
|
||||
write(1, "-2147483648", 11);
|
||||
}
|
||||
else if (nb >= 0 && nb < 10)
|
||||
{
|
||||
ft_putchar(nb + 48);
|
||||
}
|
||||
else if (nb < 0)
|
||||
{
|
||||
ft_putchar('-');
|
||||
ft_putnbr(nb * (-1));
|
||||
}
|
||||
else
|
||||
{
|
||||
ft_putnbr (nb / 10);
|
||||
ft_putnbr (nb % 10);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user