n
to the given file descriptor.void ft_putnbr_fd(int n, int fd);
n
: The integer to output.fd
: The file descriptor on which to write.#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
๋ง ๋ฐ๋ก ์ฒ๋ฆฌํจ