ft_putnbr_fd

oneยท2021๋…„ 2์›” 3์ผ
0

โœ…ft_putnbr_fd

  • Outputs the integer n to the given file descriptor.
  • ์ •์ˆ˜ 'n'์„ ์ฃผ์–ด์ง„ ํŒŒ์ผ๋””์Šคํฌ๋ฆฝํ„ฐ๋กœ ์ถœ๋ ฅ.

๐Ÿ’พPrototype

void ft_putnbr_fd(int n, int fd);

๐Ÿ’ปParameters

  • n : The integer to output.
  • fd : The file descriptor on which to write.

๐Ÿ’ปReturn value

  • None

๐Ÿ’พCode

#include "libft.h"

void	ft_putnbr_fd(int n, int fd)
{
	char	str;

	if (n == -2147483648)
	{
		ft_putnbr_fd(n / 10, fd);
		write(fd, "8", 1);
		return ;
	}
	else if (n < 0)
	{
		write(fd, "-", 1);
		n *= -1;
	}
	if (n >= 10)
	{
		ft_putnbr_fd(n / 10, fd);
		str = '0' + n % 10;
	}
	else
		str = '0' + n;
	write(fd, &str, 1);
}

๐Ÿ’ก์˜ค๋ฒ„ํ”Œ๋กœ์šฐ ๋•Œ๋ฌธ์— -2147483648๋งŒ ๋”ฐ๋กœ ์ฒ˜๋ฆฌํ•จ

profile
๋Š˜ ํ˜ธ๊ธฐ์‹ฌ์„ ๊ฐ–๊ณ , ์ƒˆ๋กœ์šด ๊ฒƒ์— ๋„์ „ํ•  ๊ฒƒ.

0๊ฐœ์˜ ๋Œ“๊ธ€