mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-05-14 00:08:47 +02:00
「✨」 feat(libft): added a very cool feature !
This commit is contained in:
35
libft/print/ft_putnbrbase_fd.c
Normal file
35
libft/print/ft_putnbrbase_fd.c
Normal file
@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbrbase_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/18 10:57:44 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:41:30 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
void ft_putnbrbase_fd(int n, char *base, int fd)
|
||||
{
|
||||
unsigned int nbr;
|
||||
size_t base_len;
|
||||
|
||||
base_len = ft_strlen(base);
|
||||
if (n < 0)
|
||||
{
|
||||
write(fd, "-", 1);
|
||||
nbr = -n;
|
||||
}
|
||||
else
|
||||
nbr = n;
|
||||
if (nbr < base_len)
|
||||
write(fd, &base[nbr % base_len], 1);
|
||||
else
|
||||
{
|
||||
ft_putnbrbase_fd(nbr / base_len, base, fd);
|
||||
write(fd, &base[nbr % base_len], 1);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user