83 lines
1.6 KiB
C
83 lines
1.6 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_convert_base2.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2026/03/17 14:22:20 by lclerel- #+# #+# */
|
|
/* Updated: 2026/03/17 18:16:30 by lclerel- ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include <unistd.h>
|
|
|
|
int ft_strlen(char *str)
|
|
{
|
|
int i;
|
|
|
|
i = 0;
|
|
while (str[i] != '\0')
|
|
{
|
|
i++;
|
|
}
|
|
return (i);
|
|
}
|
|
|
|
void ft_putstr(char *str)
|
|
{
|
|
int i;
|
|
|
|
i = 0;
|
|
while (str[i])
|
|
{
|
|
write(1, &str[i], 1);
|
|
i++;
|
|
}
|
|
}
|
|
|
|
int ft_nbrlen(long nbr, int base_size)
|
|
{
|
|
int len;
|
|
|
|
len = 0;
|
|
if (nbr <= 0)
|
|
{
|
|
len++;
|
|
if (nbr < 0)
|
|
nbr = -nbr;
|
|
}
|
|
while (nbr > 0)
|
|
{
|
|
nbr /= base_size;
|
|
len++;
|
|
}
|
|
return (len);
|
|
}
|
|
|
|
int check_base(char *base)
|
|
{
|
|
int i;
|
|
int j;
|
|
|
|
i = 0;
|
|
if (!base[0] || !base[1])
|
|
return (0);
|
|
while (base[i])
|
|
{
|
|
if (base[i] == '+' || base[i] == '-'
|
|
|| (base[i] >= 9 && base[i] <= 13)
|
|
|| base[i] == 32)
|
|
return (0);
|
|
j = i + 1;
|
|
while (base[j])
|
|
{
|
|
if (base[i] == base[j])
|
|
return (0);
|
|
j++;
|
|
}
|
|
i++;
|
|
}
|
|
return (1);
|
|
}
|