/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_show_tab.c                                      :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: jayang <[email protected]>                      +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2022/02/15 12:59:19 by jayang            #+#    #+#             */
/*   Updated: 2022/02/15 21:55:37 by jayang           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <unistd.h>
#include "ft_stock_str.h"

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

void	ft_putnbr(int nbr)
{
	if (nbr == -2147483648)
		write(1, "-2147483648", 11);
	else if (nbr < 0)
	{
		write(1, "-", 1);
		nbr *= -1;
	}
	if ((nbr > 0) && (nbr / 10 != 0))
		ft_putnbr(nbr / 10);
	ft_putchar(nbr % 10 + '0');
}

void	ft_show_tab(struct s_stock_str *par)
{
	int	idx;
	int	_i;

	idx = 0;
	while (par[idx].str)
	{
		_i = 0;
		while (par[idx].str[_i])
		{
			ft_putchar(par[idx].str[_i]);
			_i++;
		}
		ft_putchar('\\n');
		ft_putnbr(par[idx].size);
		ft_putchar('\\n');
		_i = 0;
		while (par[idx].copy[_i])
		{
			ft_putchar(par[idx].copy[_i]);
			_i++;
		}
		ft_putchar('\\n');
		idx++;
	}
}