properly started project
This commit is contained in:
36
srcs/ft_printf.c
Normal file
36
srcs/ft_printf.c
Normal file
@@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_printf.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/02/07 13:31:16 by tmaze #+# #+# */
|
||||
/* Updated: 2019/02/07 14:21:34 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libftprintf.h"
|
||||
|
||||
int ft_printf(const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
size_t i;
|
||||
size_t j;
|
||||
t_flags flags;
|
||||
static int (*convf[10])(t_flags *flags, va_list *ap) = {pf_convc,
|
||||
pf_convs, pf_convp, pf_convd, pf_convi, pf_convo, pf_convu, pf_convx,
|
||||
pf_convx, pf_convf};
|
||||
|
||||
va_start(ap, format);
|
||||
i = 0;
|
||||
while (format[i])
|
||||
{
|
||||
j = 0;
|
||||
while (format[i + j] && format[i + j] != '%')
|
||||
j++;
|
||||
write(1, &format[i], j);
|
||||
i += j;
|
||||
j = pf_getflags(&format[i], &flags);
|
||||
}
|
||||
}
|
21
srcs/ft_printf.c~
Normal file
21
srcs/ft_printf.c~
Normal file
@@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_printf.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/02/07 13:31:16 by tmaze #+# #+# */
|
||||
/* Updated: 2019/02/07 13:34:43 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libftprintf.h"
|
||||
|
||||
int ft_printf(const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
size_t i;
|
||||
|
||||
va_start();
|
||||
}
|
60
srcs/pf_getflags.c
Normal file
60
srcs/pf_getflags.c
Normal file
@@ -0,0 +1,60 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* pf_getflags.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/02/07 14:14:38 by tmaze #+# #+# */
|
||||
/* Updated: 2019/02/07 17:11:26 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libftprintf.h"
|
||||
|
||||
void pf_initflags(t_flags *flags)
|
||||
{
|
||||
flags->convtype = none;
|
||||
flags->minus = '\0';
|
||||
flags->sign = '\0';
|
||||
flags->hash = '\0';
|
||||
flags->width = 0;
|
||||
flags->precision = 0;
|
||||
flags->size = '\0';
|
||||
}
|
||||
|
||||
size_t pf_getflags(const char *format, t_flags *flags)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
pf_initflags(flags);
|
||||
i = 0;
|
||||
while (format[++i] && ft_strchr("%cspdiouxXf", format[i]) != NULL)
|
||||
{
|
||||
if (format[i] == '-')
|
||||
flags->minus = '-';
|
||||
if (format[i] == '#')
|
||||
flags->hash = '#';
|
||||
if (format[i] == ' ' || format[i] == '+')
|
||||
flags->sign = format[i];
|
||||
if (ft_isdigit(format[i])
|
||||
|| (format[i] == '.' && ft_isdigit(format[i + 1])))
|
||||
{
|
||||
if (ft_isdigit(format[i]))
|
||||
flags->width = ft_atoi(&format[i]);
|
||||
else
|
||||
flags->precision = ft_atoi(&format[i + 1]);
|
||||
while (format[i + 1] && ft_isdigit(format[i + 1]))
|
||||
i++;
|
||||
continue ;
|
||||
}
|
||||
if (format[i] == 'h' || format[i] == 'l')
|
||||
{
|
||||
flags->size = format[i];
|
||||
if (format[i + 1] && format[i + 1] == format[i])
|
||||
flags->size = ft_toupper(format[++i]);
|
||||
}
|
||||
}
|
||||
flags->convtype = format[i];
|
||||
return (i);
|
||||
}
|
18
srcs/pf_getflags.c~
Normal file
18
srcs/pf_getflags.c~
Normal file
@@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* pf_getflags.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/02/07 14:14:38 by tmaze #+# #+# */
|
||||
/* Updated: 2019/02/07 14:20:13 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libftprintf.h"
|
||||
|
||||
size_t *pf_getflags(const char *format, t_flags *flags)
|
||||
{
|
||||
|
||||
}
|
Reference in New Issue
Block a user