tout a la norme

This commit is contained in:
Hugo LAMY
2020-02-27 12:10:07 +01:00
parent c1a6c0c5ed
commit 1bc1e87c67
6 changed files with 44 additions and 12 deletions

BIN
ft_printf

Binary file not shown.

View File

@@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/27 12:07:47 by hulamy #+# #+# */
/* Updated: 2020/02/27 12:08:40 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_PRINTF_H #ifndef FT_PRINTF_H
# define FT_PRINTF_H # define FT_PRINTF_H
# include <stdlib.h> # include <stdlib.h>
@@ -7,24 +19,36 @@
# include <stdio.h> # include <stdio.h>
// ft_printf.c /*
** ft_printf.c
*/
char *specifier(char *s); char *specifier(char *s);
int ft_expand_star(int nbr, char **string); int ft_expand_star(int nbr, char **string);
int ft_put_word(char *s, char *type); int ft_put_word(char *s, char *type);
int length_n_free(int length, char *s); int length_n_free(int length, char *s);
int ft_printf(char *string, ...); int ft_printf(char *string, ...);
// ft_next_word.c /*
** ft_next_word.c
*/
int width_precision(char *s); int width_precision(char *s);
int word_length(char *s); int word_length(char *s);
char *next_word(char **s); char *next_word(char **s);
// ft_convert.c /*
** ft_convert.c
*/
char *conv_i(char c, long int i); char *conv_i(char c, long int i);
char *conv_u(char c, unsigned long int i); char *conv_u(char c, unsigned long int i);
char *ft_convert(va_list ap, char *type); char *ft_convert(va_list ap, char *type);
// ft_flag_transform.c /*
** ft_flag_transform.c
*/
char *precision_int(char *print, int precision); char *precision_int(char *print, int precision);
char *ft_precision(char *s, char *print, char *type); char *ft_precision(char *s, char *print, char *type);
char *width_flags(char *print, char *tmp, char *s, int width); char *width_flags(char *print, char *tmp, char *s, int width);

View File

View File

@@ -1,2 +0,0 @@
printf2:test1
printf2:test2

View File

@@ -1,3 +1,14 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_convert.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/27 12:03:28 by hulamy #+# #+# */
/* Updated: 2020/02/27 12:03:38 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h" #include "ft_printf.h"
@@ -73,7 +84,7 @@ char *ft_convert(va_list ap, char *type)
if ((s = ft_strchrset(type, "s"))) if ((s = ft_strchrset(type, "s")))
return (conv_u(s[0], va_arg(ap, unsigned long int))); return (conv_u(s[0], va_arg(ap, unsigned long int)));
if (ft_strchr(type, '%')) if (ft_strchr(type, '%'))
return(ft_strdup("%")); return (ft_strdup("%"));
if (ft_strchrset(type, "efgn")) if (ft_strchrset(type, "efgn"))
return (NULL); return (NULL);
return (NULL); return (NULL);

View File

@@ -6,7 +6,7 @@
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */ /* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/27 11:55:43 by hulamy #+# #+# */ /* Created: 2020/02/27 11:55:43 by hulamy #+# #+# */
/* Updated: 2020/02/27 11:55:45 by hulamy ### ########.fr */ /* Updated: 2020/02/27 12:07:22 by hulamy ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -57,7 +57,7 @@ char *precision_int(char *print, int precision)
** -if flag '0' is present in %string, removes it (actually turn each occurence ** -if flag '0' is present in %string, removes it (actually turn each occurence
** in a '.') ** in a '.')
** -and transform 'print' according to the precision : ** -and transform 'print' according to the precision :
** -0 if .precision == 0 and print == "0": return (print[0] = '\0') (print nothing) ** -0 if .precision is 0 && print is "0": print nothing
** -1 if type is s: if length(s) > precision, removes end of 'print' to print ** -1 if type is s: if length(s) > precision, removes end of 'print' to print
** only x chars, with x = precision ** only x chars, with x = precision
** -2 if type is "diouxX": call fonction 'precision_int' that return : ** -2 if type is "diouxX": call fonction 'precision_int' that return :
@@ -119,7 +119,7 @@ char *width_flags(char *print, char *tmp, char *s, int width)
} }
else else
{ {
c = (ft_strchr(s, '0')) ? '0' : ' ' ; c = (ft_strchr(s, '0')) ? '0' : ' ';
while (i < (width - ft_strlen(print))) while (i < (width - ft_strlen(print)))
tmp[i++] = c; tmp[i++] = c;
while (print[j]) while (print[j])
@@ -154,7 +154,6 @@ char *ft_width(char *s, char *print)
return (print); return (print);
} }
/* /*
** go through all the transformation flags needs ** go through all the transformation flags needs
*/ */