Push libft

125/100 corrected the 14/11/23
This commit is contained in:
Raphaël 2023-11-14 13:31:56 +01:00 committed by GitHub
commit 7bd66aee5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
45 changed files with 1462 additions and 0 deletions

55
ft_putnbr_fd.c Normal file
View file

@ -0,0 +1,55 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 13:59:18 by rparodi #+# #+# */
/* Updated: 2023/11/13 20:13:20 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_check_sign(int n, char *str, size_t *i, int fd)
{
size_t modulus;
short int maiboyerlpb;
maiboyerlpb = 0;
modulus = 1000000000;
if (n < 0)
{
n = -n;
str[(*i)] = '-';
(*i)++;
}
while (modulus != 0)
{
if (n / modulus != 0 || maiboyerlpb != 0)
{
str[(*i)++] = (n / modulus) + 48;
maiboyerlpb++;
}
n %= modulus;
modulus /= 10;
}
ft_putstr_fd(str, fd);
return (n);
}
void ft_putnbr_fd(int n, int fd)
{
size_t i;
char str[13];
i = 0;
ft_bzero(str, 13);
if (n == 0)
ft_putstr_fd("0", fd);
else if (n == -2147483648)
ft_putstr_fd("-2147483648", fd);
else
ft_check_sign(n, str, &i, fd);
}