diff --git a/.ft_printf.c.swn b/.ft_printf.c.swn index e71ca7f..90d1c0d 100644 Binary files a/.ft_printf.c.swn and b/.ft_printf.c.swn differ diff --git a/ft_next_word.c b/ft_next_word.c index 216f64f..4168b09 100644 --- a/ft_next_word.c +++ b/ft_next_word.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/10 13:58:30 by hulamy #+# #+# */ -/* Updated: 2020/02/10 13:58:34 by hulamy ### ########.fr */ +/* Updated: 2020/02/10 16:36:35 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,12 +24,12 @@ int width_precision(char *s) int i; i = 0; - if (strchr("*", s[i]) != NULL) + if (ft_strchr("*", s[i]) != NULL) i++; - else if (strchr("123456789", s[i]) != NULL) + else if (ft_strchr("123456789", s[i]) != NULL) { i++; - while (strchr("0123456789", s[i]) != NULL) + while (ft_strchr("0123456789", s[i]) != NULL) i++; } return (i); @@ -62,19 +62,17 @@ int word_length(char *s) { while (s[i] != '%' && s[i] != '\0') i++; - printf("%02i.:",i); return (i); } - while (strchr("#0- +'", s[i]) != NULL) + while (ft_strchr("#0- +'", s[i]) != NULL) i++; i += width_precision(s + i); - if (strchr(".", s[i]) != NULL) + if (ft_strchr(".", s[i]) != NULL) i += width_precision(s + i + 1) + 1; - if (strchr("hl", s[i]) != NULL) + while (ft_strchr("hl", s[i]) != NULL) i++; - if (strchr("diuxXcspefgn%", s[i]) != NULL) + if (ft_strchr("diuxXcspefgn%", s[i]) != NULL) i++; - printf("%02i::",i); return (i); } @@ -95,13 +93,10 @@ char *next_word(char **string) if (*s == '\0') return (NULL); if ((i = word_length(s)) < 0) - { - printf("error\n"); return (NULL); - } word = (char *)malloc(sizeof(char) * (i + 1)); word[i] = '\0'; - memmove(word, s, i); + ft_memmove(word, s, i); *string += i; return (word); } diff --git a/ft_printf b/ft_printf index 5dd0f57..9bbddd4 100755 Binary files a/ft_printf and b/ft_printf differ diff --git a/ft_printf.c b/ft_printf.c index 02112ed..537ebf3 100644 --- a/ft_printf.c +++ b/ft_printf.c @@ -10,7 +10,7 @@ ** | by va_arg ** while s = next_word() | -return the next sequence to be print ** | (either a string, or a conversion) -** type = ft_specifier(&s) | -return the type if it's a conversion, or "%", +** type = specifier(&s) | -return the type if it's a conversion, or "%", ** | or NULL if it's a string. if it's a ** | single '%' it's considered as a string ** | if convers0, rmvs length & specifier from s @@ -24,13 +24,30 @@ ** return (length) | -return the length of what was printed ** ** char *next_word(char *s); -** char *ft_specifier(char **s); +** char *specifier(char **s); ** int ft_put_words(char *s); ** void ft_expand_star(int i, char **s); ** char *ft_convert(va_list ap, char *type); ** char *ft_flag_transform(char *s, char *print); */ +char *specifier(char **string) +{ + char *s; + int i; + + s = *string; + printf("[%s]\n", s); + if (s[0] != '%' || s[1] == '\0') + return (NULL); + if (s[1] == '%') + return (ft_strdup("%")); + i = 1; + while (ft_strchr("#0- +'0123456789.*", s[i]) != NULL) + i++; + return (ft_strdup(s + i)); +} + int ft_printf(char *string, ...) { char *s; @@ -42,12 +59,13 @@ int ft_printf(char *string, ...) length = 0; va_start(ap, string); while ((s = next_word(&string)) != NULL) - { - printf("[%s]\n", s); - (void)print; - (void)type; - length = 1; - // if (!(type = ft_specifier(&s))) + { // TEST NEXT_WORD : printf("[%s]\n", s); (void)print; (void)type; length = 1; + if (!(type = specifier(&s))) + { + (void)print; + length = 1; + } + printf(" %s\n", type); // lentgh += ft_put_word(s); // while (ft_strchr(s, '*')) // ft_expand_star(va_arg(ap, int), &s); diff --git a/ft_printf.h b/ft_printf.h index d9651b3..aa99de9 100644 --- a/ft_printf.h +++ b/ft_printf.h @@ -3,6 +3,7 @@ # include # include # include +# include "libft.c/libft.h" # include