feat: added ft_putnbr and ft-putunbr
This commit is contained in:
parent
9bf197acbd
commit
2a9b042122
2 changed files with 35 additions and 0 deletions
21
srcs/ft_putnbr.c
Normal file
21
srcs/ft_putnbr.c
Normal 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;
|
||||
}
|
||||
14
srcs/ft_putunbr.c
Normal file
14
srcs/ft_putunbr.c
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#include "libft.h"
|
||||
#include <unistd.h>
|
||||
|
||||
int ft_putunbr(unsigned int n)
|
||||
{
|
||||
int count = 0;
|
||||
char c;
|
||||
|
||||
if (n >= 10)
|
||||
count += ft_putunbr(n / 10);
|
||||
c = '0' + (n % 10);
|
||||
count += ft_putchar(c);
|
||||
return count;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue