correction length et debut ecriture type

This commit is contained in:
Hugo LAMY
2020-02-10 16:37:01 +01:00
parent 89f82989e7
commit a00248d7ef
5 changed files with 36 additions and 22 deletions

Binary file not shown.

View File

@@ -6,7 +6,7 @@
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

BIN
ft_printf

Binary file not shown.

View File

@@ -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);

View File

@@ -3,6 +3,7 @@
# include <stdlib.h>
# include <stdio.h>
# include <stdarg.h>
# include "libft.c/libft.h"
# include <libc.h>