ex00

int	ft_strlen(char *str)

{
	int	i;

	i = 0;
	while (str[i] != '\0')
	{		
		i++;
	}
	return (i);
}

ex01

#include<unistd.h>

void	ft_putstr(char *str)

{
	int	i;

	i = 0;
	while (str[i] != '\0')
	{
		write(1, &str[i], 1);
		i++;
	}
}

ex02

#include<unistd.h>

void	ft_putnbr(int nb)

{
	int	a;

	if (nb == -2147483648)
	{
		write(1, "-2147483648", 11);
		return ;
	}
	if (nb < 0)
	{
		nb = nb * -1;
		write(1, "-", 1);
		ft_putnbr(nb);
	}
	else if (nb < 10)
	{
		a = nb + 48;
		write(1, &a, 1);
	}
	else if (nb >= 10)
	{
		ft_putnbr(nb / 10);
		ft_putnbr(nb % 10);
	}
}

ex03

03.ft_atoi

Screenshot from 2024-01-26 09-45-54.png

중요한개념- 화이트 스페이스, “-”, 문자 전까지 숫자 출력

result = (result * 10 ) + (str[a] - ‘0’)

int	ft_atoi(char *str)

{
	int	a;
	int	i;
	int	result;

	a = 0;
	i = 1;
	result = 0;
	while ((str[a] >= 9 && str[a] <= 13) || str[a] == 32)
		a++;
	while (str[a] == '-' || str[a] == '+')
	{	
		if (str[a] == '-')
			i *= -1;
		a++;
	}
	while (str[a] >= '0' && str[a] <= '9')
	{
		result = (result * 10) + (str[a] - '0');
		a++;
	}
	return (result * i);
}

ex04

#include<unistd.h>
#include<stdio.h>

int	llength(char *str)

{
	int	i;

	i = 0;
	while (str[i] != '\0')
	{
		i++;
	}
	return (i);
}

void	ft_putchar(char c)

{
	write(1, &c, 1);
}

int	check_base(char *s1)

{
	int	i;
	int	j;

	i = llength(s1);
	if (i == 1 || s1[0] == '\0')
		return (0);
	i = 0;
	while (s1[i] != '\0')
	{
		if (s1[i] == '+' || s1[i] == '-')
			return (0);
		j = i + 1;
		while (s1[j] != '\0')
		{	
			if (s1[i] == s1[j])
				return (0);
			j++;
		}
		i++;
	}
	return (1);
}

int	result_base(long long nbr, char *base, long long size)

{
	long long				a;
	int						c;

	if (nbr < 0)
	{
		a = nbr * -1;
	}
	else
		a = nbr;
	if (a >= size)
		result_base(nbr / size, base, size);
	c = base[a % size];
	ft_putchar(c);
	return (0);
}

void	ft_putnbr_base(int nbr, char *base)

{
	int	i;

	i = 0;
	if (!check_base(base))
		return ;
	if (nbr < 0)
		ft_putchar('-');
	if (check_base(base) == 1)
	{
		while (base[i] != '\0')
			i++;
		result_base(nbr, base, i);
	}
}