base struct

This commit is contained in:
gazhonsepaskwa
2025-01-13 13:21:53 +01:00
parent a7e1a55200
commit 09c2cb5b3e
47 changed files with 1835 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_put_u_base.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/25 09:01:21 by nalebrun #+# #+# */
/* Updated: 2024/11/25 16:15:43 by nalebrun ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../libft.h"
int ft_put_ui_base(unsigned int nbr, char *base)
{
unsigned int base_len;
int count;
int tmp;
count = 0;
base_len = ft_strlen(base);
if (base_len < 2)
return (0);
if (nbr >= base_len)
{
tmp = ft_put_ui_base(nbr / base_len, base);
if (tmp == -1)
return (-1);
count += tmp;
}
tmp = write(1, &base[nbr % base_len], 1);
if (tmp == -1)
return (-1);
return (tmp + count);
}
int ft_put_uli_base(unsigned long int nbr, char *base)
{
unsigned long base_len;
int count;
int tmp;
count = 0;
base_len = ft_strlen(base);
if (base_len < 2)
return (0);
if (nbr >= base_len)
count += ft_put_uli_base(nbr / base_len, base);
tmp = write(1, &base[nbr % base_len], 1);
if (tmp == -1)
return (-1);
return (tmp + count);
}