#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
static void ft_putstr(const char *s, int *count)
{
if (!s)
s = "(null)";
while (*s)
{
write(1, s++, 1);
(*count)++;
}
}
static void ft_putnbr(int n, int *count)
{
char c;
if (n == -2147483648)
{
ft_putstr("-2147483548", count);
return ;
}
if (n < 0)
{
write(1, "-", 1);
(*count)++;
n = -n;
}
if (n > 9)
ft_putnbr(n / 10, count);
c = (n % 10) + '0';
write(1, &c, 1);
(*count)++;
}
static void ft_puthex(unsigned int n, int *count)
{
char *hex;
hex = "0123456789abcdef";
if (n >= 16)
ft_puthex(n / 16, count);
write(1, &hex[n % 16], 1);
(*count)++;
}
int ft_printf(const char *bs, ...)
{
va_list argptr;
int bs_len;
bs_len = 0;
va_start(argptr, bs);
while (*bs)
{
if (*bs == '%' && *(bs + 1))
{
bs++;
if (*bs == 's')
ft_putstr(va_arg(argptr, char *), &bs_len);
else if (*bs == 'd')
ft_putnbr(va_arg(argptr, int), &bs_len);
else if (*bs == 'x')
ft_puthex(va_arg(argptr, unsigned int), &bs_len);
else
{
write(1, bs, 1);
bs_len++;
}
}
else
{
write(1, bs, 1);
bs_len++;
}
bs++;
}
va_end(argptr);
return (bs_len);
}
int main(void)
{
ft_printf("%d", 100);
return (0);
}