Browse Source

removed useless printf

master
nicolas-arnaud 2 years ago
parent
commit
2cd8ed5527
  1. 39
      printf/ft_printf.c
  2. 58
      printf/ft_putchars.c
  3. 47
      printf/ft_putnbrs.c
  4. 31
      printf/ft_putptr.c
  5. 47
      printf/ft_putx.c

39
printf/ft_printf.c

@ -1,39 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/27 08:09:49 by narnaud #+# #+# */
/* Updated: 2021/11/17 09:40:16 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include "ft_printf.h"
int ft_printf(const char *str, ...)
{
va_list args;
size_t n;
size_t i;
const char *g_types = {"cspdiuxX%"};
static int (*g_printf_fcts[9])(va_list arg, const char *str) = {\
va_putchar, va_putstr, va_putptr, va_putnbr, va_putnbr, va_putunsign, \
va_putx, va_putx_cap, va_putperc};
i = 0;
va_start (args, str);
while (*str)
{
n = -1;
if ((*str == '%' && str++) || !(++i && ft_putchar((int)*str)))
while (++n < 9)
if (g_types[n] == *str)
i += (g_printf_fcts[n])(args, str);
str++;
}
va_end(args);
return (i);
}

58
printf/ft_putchars.c

@ -1,58 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchars.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/27 09:17:03 by narnaud #+# #+# */
/* Updated: 2021/11/17 09:57:53 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putchar(int ch)
{
char c;
c = (char)ch;
write(1, &c, 1);
return (1);
}
int ft_putstr(char *str)
{
int i;
i = 0;
if (!str)
{
ft_putstr("(null)");
return (6);
}
while (str[i])
ft_putchar(str[i++]);
return (i);
}
int va_putchar(va_list va_ch, const char *str)
{
(void)*str;
ft_putchar(va_arg(va_ch, int));
return (1);
}
int va_putstr(va_list va_str, const char *str)
{
(void)*str;
return (ft_putstr(va_arg(va_str, char *)));
}
int va_putperc(va_list va, const char *str)
{
(void)*str;
(void)va;
ft_putchar('%');
return (1);
}

47
printf/ft_putnbrs.c

@ -1,47 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbrs.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/27 09:34:01 by narnaud #+# #+# */
/* Updated: 2021/12/21 10:06:28 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putnbr(int n, const char *str)
{
char *n_str;
int ret;
(void)*str;
n_str = ft_itoa(n);
ret = ft_putstr(n_str);
free(n_str);
return (ret);
}
int ft_putunsign(unsigned int n, const char *str)
{
char *n_str;
int ret;
(void)*str;
n_str = ft_utoa(n);
ret = ft_putstr(n_str);
free(n_str);
return (ret);
}
int va_putnbr(va_list va, const char *str)
{
return (ft_putnbr(va_arg(va, int), str));
}
int va_putunsign(va_list va, const char *str)
{
return (ft_putunsign(va_arg(va, unsigned int), str));
}

31
printf/ft_putptr.c

@ -1,31 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putptr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/27 10:13:07 by narnaud #+# #+# */
/* Updated: 2021/12/21 09:50:41 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putptr(void *ptr)
{
char *str;
int ret;
str = ft_itox((unsigned long long int)ptr, "0123456789abcdef");
ft_putstr("0x");
ret = ft_putstr(str);
free(str);
return (ret + 2);
}
int va_putptr(va_list va_ptr, const char *str)
{
(void)*str;
return (ft_putptr(va_arg(va_ptr, void *)));
}

47
printf/ft_putx.c

@ -1,47 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putx.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/27 09:54:24 by narnaud #+# #+# */
/* Updated: 2021/11/17 10:24:24 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putx(unsigned int n)
{
char *str;
int ret;
str = ft_itox((unsigned long int)n, "0123456789abcdef");
ret = ft_putstr(str);
free(str);
return (ret);
}
int ft_putx_cap(unsigned int n)
{
char *str;
int ret;
str = ft_itox((unsigned long int)n, "0123456789ABCDEF");
ret = ft_putstr(str);
free(str);
return (ret);
}
int va_putx(va_list va_uint, const char *str)
{
(void)*str;
return (ft_putx(va_arg(va_uint, unsigned int)));
}
int va_putx_cap(va_list va_uint, const char *str)
{
(void)*str;
return (ft_putx_cap(va_arg(va_uint, unsigned int)));
}
Loading…
Cancel
Save