/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* printing.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/05 04:09:39 by tischmid #+# #+# */ /* Updated: 2023/04/05 10:19:12 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ #include "printing.h" void ft_putchar(char c) { write(1, &c, 1); } int ft_err(char *str, int exit_code) { ft_putstr(RED); ft_putstr(str); ft_putstr(CLR_RST); return (exit_code); } void ft_putstr(char *str) { while (*str) ft_putchar(*str++); } void ft_putnbr(int nb) { if (nb > 9) { ft_putnbr(nb / 10); ft_putchar(nb % 10 + '0'); } else if (nb == INT_MIN) { ft_putnbr(nb / 10); ft_putnbr(-(nb % 10)); } else if (nb < 0) { ft_putchar('-'); ft_putnbr(-nb); } else ft_putchar(nb % 10 + '0'); } void print_map(t_map *map, int as_numbers) { int i; int j; i = -1; while (++i < map->meta.height) { j = -1; while (++j < map->meta.width) { if (as_numbers) { ft_putnbr(map->data[i * map->meta.width + j]); } else ft_putchar(map->data[i * map->meta.width + j]); } ft_putchar('\n'); } }