Add fd to printing functions, so errors can be put to stderr

This commit is contained in:
Timo Schmidt 2023-04-05 11:02:52 +02:00
parent 998974c177
commit f90434ced9
2 changed files with 16 additions and 16 deletions

View File

@ -6,7 +6,7 @@
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/05 04:11:08 by tischmid #+# #+# */
/* Updated: 2023/04/05 10:01:56 by tischmid ### ########.fr */
/* Updated: 2023/04/05 11:01:41 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,8 +20,8 @@
# define YLW "\x1b[33m"
# define CLR_RST "\x1b[m"
void ft_putchar(char c);
void ft_putstr(char *str);
void ft_putchar(char c, int fd);
void ft_putstr(char *str, int fd);
void ft_putnbr(int nb);
void print_map(t_map *map, int as_numbers);
int ft_err(char *str, int exit_code);

View File

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