본문 바로가기
프로젝트/42Seoul

42서울 라피신 1주차 (Rush00)

by soohykim 2025. 4. 9.
728x90
반응형

main.c

void	rush(int x, int y);

int	ft_atoi(char *str)
{
	long long	val;
	char		*save;

	val = 0;
	save = str;
	while (*str)
	{
		if (*str < '0' || *str > '9')
			return (0);
		str++;
	}
	str = save;
	while (*str && *str >= '0' && *str <= '9')
	{
		val = val * 10 + *str - '0';
		if (val > 2147483647)
			return (0);
		str++;
	}
	return ((int)val);
}

int	main(int argc, char *argv[])
{
	int	x;
	int	y;

	if (argc != 3)
		return (0);
	x = ft_atoi(argv[1]);
	y = ft_atoi(argv[2]);
	if (x == 0 || y == 0)
		return (0);
	rush(x, y);
	return (0);
}

ft_putchar.c

#include <unistd.h>

void	ft_putchar(char c)
{
	write(1, &c, 1);
}

rush04.c (필수)

void	ft_putchar(char c);

void	rush(int x, int y)
{
	int	i;
	int	j;

	j = 1;
	while (j <= y)
	{
		i = 1;
		while (i <= x)
		{
			if (i == 1 && j == 1)
				ft_putchar('A');
			else if ((i == x && j == 1) || (i == 1 && j == y))
				ft_putchar('C');
			else if (i == x && j == y)
				ft_putchar('A');
			else if (i == 1 || j == 1 || i == x || j == y)
				ft_putchar('B');
			else
				ft_putchar(' ');
			i++;
		}
		ft_putchar('\n');
		j++;
	}
}

rush00.c (선택)

void	ft_putchar(char c);

void	rush(int x, int y)
{
	int	i;
	int	j;

	j = 1;
	while (j <= y)
	{
		i = 1;
		while (i <= x)
		{
			if ((i == 1 || i == x) && (j == 1 || j == y))
				ft_putchar('o');
			else if (i == 1 || i == x)
				ft_putchar('|');
			else if (j == 1 || j == y)
				ft_putchar('-');
			else
				ft_putchar(' ');
			i++;
		}
		ft_putchar('\n');
		j++;
	}
}

rush01.c (선택)

void	ft_putchar(char c);

void	rush(int x, int y)
{
	int	i;
	int	j;

	j = 1;
	while (j <= y)
	{
		i = 1;
		while (i <= x)
		{
			if (i == 1 && j == 1)
				ft_putchar('/');
			else if ((i == x && j == 1) || (i == 1 && j == y))
				ft_putchar('\\');
			else if (i == x && j == y)
				ft_putchar('/');
			else if (i == 1 || j == 1 || i == x || j == y)
				ft_putchar('*');
			else
				ft_putchar(' ');
			i++;
		}
		ft_putchar('\n');
		j++;
	}
}

rush02.c (선택)

void	ft_putchar(char c);

void	rush(int x, int y)
{
	int	i;
	int	j;

	j = 1;
	while (j <= y)
	{
		i = 1;
		while (i <= x)
		{
			if ((i == 1 && j == 1) || (i == x && j == 1))
				ft_putchar('A');
			else if ((i == 1 && j == y) || (i == x && j == y))
				ft_putchar('C');
			else if (i == 1 || j == 1 || i == x || j == y)
				ft_putchar('B');
			else
				ft_putchar(' ');
			i++;
		}
		ft_putchar('\n');
		j++;
	}
}

rush03.c (선택)

void	ft_putchar(char c);

void	rush(int x, int y)
{
	int	i;
	int	j;

	j = 1;
	while (j <= y)
	{
		i = 1;
		while (i <= x)
		{
			if ((i == 1 && j == 1) || (i == 1 && j == y))
				ft_putchar('A');
			else if ((i == x && j == 1) || (i == x && j == y))
				ft_putchar('C');
			else if (i == 1 || j == 1 || i == x || j == y)
				ft_putchar('B');
			else
				ft_putchar(' ');
			i++;
		}
		ft_putchar('\n');
		j++;
	}
}
728x90
반응형