correction length et debut ecriture type
This commit is contained in:
BIN
.ft_printf.c.swn
BIN
.ft_printf.c.swn
Binary file not shown.
@@ -6,7 +6,7 @@
|
|||||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2020/02/10 13:58:30 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;
|
int i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if (strchr("*", s[i]) != NULL)
|
if (ft_strchr("*", s[i]) != NULL)
|
||||||
i++;
|
i++;
|
||||||
else if (strchr("123456789", s[i]) != NULL)
|
else if (ft_strchr("123456789", s[i]) != NULL)
|
||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
while (strchr("0123456789", s[i]) != NULL)
|
while (ft_strchr("0123456789", s[i]) != NULL)
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return (i);
|
return (i);
|
||||||
@@ -62,19 +62,17 @@ int word_length(char *s)
|
|||||||
{
|
{
|
||||||
while (s[i] != '%' && s[i] != '\0')
|
while (s[i] != '%' && s[i] != '\0')
|
||||||
i++;
|
i++;
|
||||||
printf("%02i.:",i);
|
|
||||||
return (i);
|
return (i);
|
||||||
}
|
}
|
||||||
while (strchr("#0- +'", s[i]) != NULL)
|
while (ft_strchr("#0- +'", s[i]) != NULL)
|
||||||
i++;
|
i++;
|
||||||
i += width_precision(s + i);
|
i += width_precision(s + i);
|
||||||
if (strchr(".", s[i]) != NULL)
|
if (ft_strchr(".", s[i]) != NULL)
|
||||||
i += width_precision(s + i + 1) + 1;
|
i += width_precision(s + i + 1) + 1;
|
||||||
if (strchr("hl", s[i]) != NULL)
|
while (ft_strchr("hl", s[i]) != NULL)
|
||||||
i++;
|
i++;
|
||||||
if (strchr("diuxXcspefgn%", s[i]) != NULL)
|
if (ft_strchr("diuxXcspefgn%", s[i]) != NULL)
|
||||||
i++;
|
i++;
|
||||||
printf("%02i::",i);
|
|
||||||
return (i);
|
return (i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,13 +93,10 @@ char *next_word(char **string)
|
|||||||
if (*s == '\0')
|
if (*s == '\0')
|
||||||
return (NULL);
|
return (NULL);
|
||||||
if ((i = word_length(s)) < 0)
|
if ((i = word_length(s)) < 0)
|
||||||
{
|
|
||||||
printf("error\n");
|
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
|
||||||
word = (char *)malloc(sizeof(char) * (i + 1));
|
word = (char *)malloc(sizeof(char) * (i + 1));
|
||||||
word[i] = '\0';
|
word[i] = '\0';
|
||||||
memmove(word, s, i);
|
ft_memmove(word, s, i);
|
||||||
*string += i;
|
*string += i;
|
||||||
return (word);
|
return (word);
|
||||||
}
|
}
|
||||||
|
|||||||
34
ft_printf.c
34
ft_printf.c
@@ -10,7 +10,7 @@
|
|||||||
** | by va_arg
|
** | by va_arg
|
||||||
** while s = next_word() | -return the next sequence to be print
|
** while s = next_word() | -return the next sequence to be print
|
||||||
** | (either a string, or a conversion)
|
** | (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
|
** | or NULL if it's a string. if it's a
|
||||||
** | single '%' it's considered as a string
|
** | single '%' it's considered as a string
|
||||||
** | if convers0, rmvs length & specifier from s
|
** | if convers0, rmvs length & specifier from s
|
||||||
@@ -24,13 +24,30 @@
|
|||||||
** return (length) | -return the length of what was printed
|
** return (length) | -return the length of what was printed
|
||||||
**
|
**
|
||||||
** char *next_word(char *s);
|
** char *next_word(char *s);
|
||||||
** char *ft_specifier(char **s);
|
** char *specifier(char **s);
|
||||||
** int ft_put_words(char *s);
|
** int ft_put_words(char *s);
|
||||||
** void ft_expand_star(int i, char **s);
|
** void ft_expand_star(int i, char **s);
|
||||||
** char *ft_convert(va_list ap, char *type);
|
** char *ft_convert(va_list ap, char *type);
|
||||||
** char *ft_flag_transform(char *s, char *print);
|
** 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, ...)
|
int ft_printf(char *string, ...)
|
||||||
{
|
{
|
||||||
char *s;
|
char *s;
|
||||||
@@ -42,12 +59,13 @@ int ft_printf(char *string, ...)
|
|||||||
length = 0;
|
length = 0;
|
||||||
va_start(ap, string);
|
va_start(ap, string);
|
||||||
while ((s = next_word(&string)) != NULL)
|
while ((s = next_word(&string)) != NULL)
|
||||||
{
|
{ // TEST NEXT_WORD : printf("[%s]\n", s); (void)print; (void)type; length = 1;
|
||||||
printf("[%s]\n", s);
|
if (!(type = specifier(&s)))
|
||||||
(void)print;
|
{
|
||||||
(void)type;
|
(void)print;
|
||||||
length = 1;
|
length = 1;
|
||||||
// if (!(type = ft_specifier(&s)))
|
}
|
||||||
|
printf(" %s\n", type);
|
||||||
// lentgh += ft_put_word(s);
|
// lentgh += ft_put_word(s);
|
||||||
// while (ft_strchr(s, '*'))
|
// while (ft_strchr(s, '*'))
|
||||||
// ft_expand_star(va_arg(ap, int), &s);
|
// ft_expand_star(va_arg(ap, int), &s);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
# include <stdarg.h>
|
# include <stdarg.h>
|
||||||
|
# include "libft.c/libft.h"
|
||||||
|
|
||||||
# include <libc.h>
|
# include <libc.h>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user