nicolas-arnaud
2 years ago
5 changed files with 0 additions and 222 deletions
@ -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); |
|||
} |
@ -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); |
|||
} |
@ -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)); |
|||
} |
@ -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 *))); |
|||
} |
@ -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…
Reference in new issue