norming & cleaning ft_putnbr & ft_putnbr_fd
This commit is contained in:
parent
0ecdc73ca9
commit
8c2756952c
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/04/08 12:52:53 by tmaze #+# #+# */
|
/* Created: 2018/04/08 12:52:53 by tmaze #+# #+# */
|
||||||
/* Updated: 2018/04/08 12:54:35 by tmaze ### ########.fr */
|
/* Updated: 2018/04/08 15:33:50 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,5 +14,5 @@
|
|||||||
|
|
||||||
void ft_putnbr(int n)
|
void ft_putnbr(int n)
|
||||||
{
|
{
|
||||||
ft_putstr(ft_itoa(n));
|
ft_putnbr_fd(n, 1);
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,35 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/04/08 13:05:24 by tmaze #+# #+# */
|
/* Created: 2018/04/08 13:05:24 by tmaze #+# #+# */
|
||||||
/* Updated: 2018/04/08 13:06:15 by tmaze ### ########.fr */
|
/* Updated: 2018/04/08 15:41:23 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
void ft_putnbr_fd(int n, int fd)
|
static unsigned long ft_abs(int n)
|
||||||
{
|
{
|
||||||
ft_putstr_fd(ft_itoa(n), fd);
|
if (n < 0)
|
||||||
|
return ((unsigned long)n * -1);
|
||||||
|
return ((unsigned long)n);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_putnbr_fd(int n, int fd)
|
||||||
|
{
|
||||||
|
unsigned long mult;
|
||||||
|
int nb_nbr;
|
||||||
|
unsigned long nbr;
|
||||||
|
|
||||||
|
mult = 10;
|
||||||
|
nbr = ft_abs(n);
|
||||||
|
while (mult < nbr)
|
||||||
|
mult *= 10;
|
||||||
|
if (n < 0)
|
||||||
|
write(fd, "-", 1);
|
||||||
|
while (mult > 1)
|
||||||
|
{
|
||||||
|
nb_nbr = '0' + ((nbr % mult) / (mult / 10));
|
||||||
|
write(fd, &nb_nbr, 1);
|
||||||
|
mult /= 10;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user