Add ft_putnbr.c

This commit is contained in:
tosu 2023-03-17 02:15:59 +01:00
parent 7d6aa7b28c
commit 04b4291970
1 changed files with 50 additions and 0 deletions

50
ex07/ft_putnbr.c Normal file
View File

@ -0,0 +1,50 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_reverse_alphabet.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/15 21:50:37 by tischmid #+# #+# */
/* Updated: 2023/03/16 05:00:01 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putnbr(int nb)
{
char last_digit;
if (nb < 0)
{
write(1, "-", 1);
if (nb == 1 << 31)
{
nb += 2e9;
write(1, "2", 1);
}
nb *= -1;
}
last_digit = nb % 10 + 0x30;
if (nb > 9)
{
nb /= 10;
ft_putnbr(nb);
}
write(1, &last_digit, 1);
}
/* ////
int main(void)
{
ft_putnbr(-2147483648);
// ft_putnbr(-10000);
// ft_putnbr(-1);
// ft_putnbr(0);
// ft_putnbr(1);
// ft_putnbr(10000);
// ft_putnbr(2147483647);
return (0);
}
*/ ////