tests repetition des flags et pseudo ecriture de delimiter mots

This commit is contained in:
Hugo LAMY
2020-02-09 18:48:11 +01:00
parent 513efb05b3
commit 4970237428
2 changed files with 387 additions and 23 deletions

View File

@@ -30,30 +30,98 @@
** char *ft_flag_transform(char *s, char *print);
*/
int isword(char *s)
{
int i;
if ('\0')
return (0);
i = 0;
if (s[i] != %)
{
while (s[i] != %)
i++;
return (i);
}
i = 1;
while (strchr(s[i],"#0- +'"))
i++;
if (*)
i++;
else if (1,2,3,4,5,6,7,8,9)
{
i++;
while (0,1,2,3,4,5,6,7,8,9)
i++;
}
if (.)
{
i++;
if (*)
i++;
else if (1,2,3,4,5,6,7,8,9)
{
i++;
while (0,1,2,3,4,5,6,7,8,9)
i++;
}
}
if (h,hh,l,ll)
i++;
if (!(d,i,u,x,X,c,s,p,%,e,f,g,n))
return (-1);
return (i);
// if (*s == '\0')
// return (0);
// return (1);
}
char *next_word(char **string)
{
char *s;
char *word;
int i;
s = *string;
if (*s == '\0')
return (NULL);
i = isword(s);
word = (char *)malloc(sizeof(char) * (i + 1));
word[i] = '\0';
memmove(word, s, i);
*string += i;
return (word);
}
int ft_printf(char *string, ...)
{
// char *print;
// char *type;
// int length;
// va_list ap;
//
// length = 0;
// va_start(ap, string);
// while ((s = next_word(str)) != NULL)
// {
// if (!(type = ft_specifier(&s)))
// lentgh += ft_put_word(s);
// while (ft_strchr(s, '*'))
// ft_expand_star(va_arg(ap, int), &s);
// if (*type == '%')
// print = ft_strdup("%");
// else
// print = ft_convert(ap, type);
// print = ft_flag_transform(s, print);
// length += ft_put_word(print);
// }
// return (length)
//}
char *s;
char *print;
char *type;
int length;
va_list ap;
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)))
// lentgh += ft_put_word(s);
// while (ft_strchr(s, '*'))
// ft_expand_star(va_arg(ap, int), &s);
// if (*type == '%')
// print = ft_strdup("%");
// else
// print = ft_convert(ap, type);
// print = ft_flag_transform(s, print);
// length += ft_put_word(print);
}
return (length);
}
/*
** if i = flag_p(&s) | -precision is calculated before width,
@@ -103,6 +171,8 @@ int ft_printf(char *string, ...)
// print = ft_alternate_form(print) //
// }
int ft_printf_test(char *string, ...)
{
t_prist *lst;
va_list ap;
@@ -128,11 +198,12 @@ int main(void)
char c;
int i;
s = "csd";
s = "csd erre rtgrtg wer";
c = 'p';
str = "bravo";
i = 6;
printf("%s-%s-%c-%i\n\n", s, str, c, i);
// ft_printf_test(s, c, str, i);
ft_printf(s, c, str, i);
return (0);
}
@@ -147,6 +218,78 @@ conversions : nfge
% [flags 0,- ][width *][.precision *] [specifier d,i,u,x,X,c,s,p,% ]
% [flags #,', ,+] [length hh,h,ll,l ][specifier e,f,g,n ]
[flags]
- left-justify within the given field width
0 left-pads the number with zeroes (0) instead of spaces, where
padding is specified (see width sub-specifier)
( + forces to precede the result with a plus or minus sign even for
positive numbers)
( (space) if no sign is going to be written, a blank space is inserted
before the value)
( # (o, x, X, a, A, e, E, f, F, g, G) used with (o, x or X) the
value is preceded with 0, 0x or 0X for values different than
zero. used with (e, E or f), it forces the written output to
contain a decimal point even if no digits would follow. by
default, if no digits follow, no decimal point is written. used
with (g or G) the result is the same as with e or E but trailing
zeros are not removed
( ' (d, u, i, f, F) used with d, u or i, or the integral portion of
a float f or F, the decimal conversions are printed by groups of
thousands separated by the non-monetary separator returned by
localeconv(3) (ex 123456789 -> 123,456,789)
[width]
(nbr) minimum number of characters to be printed. if the value to be
printed is shorter than this number, the result is padded with
blank spaces. The value is not truncated even if the result is
larger
* the width is not specified in the format string, but as an
additional integer value argument preceding the argument that
has to be formatted
[.precision]
.nbr fot integer specifiers (d,i,o,x,X) - precision specifies the
minimum number of digits to be written. If the value to be
written is shorter than this number, the result is padded with
leading zeros. The value is not truncated even if the result is
longer. A precision of 0 means that no character is written for
the value 0. For e, E and f specifiers this is the number of
digits to be printed after the decimal point. For g and G
specifiers This is the maximum number of significant digits
to be printed. For s this is the maximum number of characters
to be printed. By default all characters are printed until the
ending null character is encountered. For c type it has no
effect. When no precision is specified, the default is 1. If the
period is specified without an explicit value for precision, 0
is assumed
.* the precision is not specified in the format string, but as an
additional integer value argument preceding the argument that
has to be formated
[specifiers]
c char character
s *char string of characters
p * pointer adress
d int (or i) signed decimal integer
i int (or d) signed decimal integer
u int unsigned decimal integer
x int unsigned hexadecimal integer
X int unsigned hexadecimal integer (capital letters)
( n *int nothing printed
( f float decimal floating point
( e float scientific notation (mantissa/exponent) using e
( g float uses the shorter of %e or %f
((F float
((E float scientific notation (mantissa/exponent) using E
((G float uses the shorter of %E or %f
((o int signed octal
((C char treated as c with l modifier
((a float
((A float
((S *char treated as s with l modifier
p == long unsigned int
char 1bytes 8bits

221
main.c
View File

@@ -1,4 +1,6 @@
#include "ft_printf.h"
#include <libc.h>
#include <locale.h>
int main(void)
{
@@ -6,6 +8,7 @@ int main(void)
char c;
int i;
setlocale(LC_ALL, "en_US.UTF-8");
str = "bravo";
c = 'c';
i = 6;
@@ -261,6 +264,217 @@ int main(void)
// printf("(\"%%*.*i\",3,2,1) ft : "); ft_printf("'%*.*i'\n", 3, 2, 1);
printf("(\"%%*.*i\",3,2,1) : "); printf("'%*.*i'\n", 3, 2, 1); printf("\n");
printf("-----------------------------------------------\n");
printf("- TESTS REPETITIONS -\n");
printf("- nbr of [#0-+ '] -\n");
printf("-----------------------------------------------\n\n");
printf("(\"%%i'\", 33333) : "); printf("'%i'\n", 33333); printf("\n");
printf("(\"%%.0f\", 33333.0) : "); printf("'%.0f'\n", 33333.0); printf("\n");
printf("(\"%%#.0f\", 33333.0) : "); printf("'%#.0f'\n", 33333.0); printf("\n");
printf("(\"%%08i\", 33333) : "); printf("'%08i'\n", 33333); printf("\n");
printf("(\"%%-8i\", 33333) : "); printf("'%-8i'\n", 33333); printf("\n");
printf("(\"%%+i\", 33333) : "); printf("'%+i'\n", 33333); printf("\n");
printf("(\"%% i\", 33333) : "); printf("'% i'\n", 33333); printf("\n");
printf("(\"%%'i\", 33333) : "); printf("'%'i'\n", 33333); printf("\n");
printf("- repetition with ''' -------------------------\n");
printf("- (repeatable additionable unordered) rau -----\n\n");
printf("(\"%%''''i\", 33333) : "); printf("'%''''i'\n", 33333); printf("\n");
printf("(\"%%'#.0f\", 33333.0) : "); printf("'%'#.0f'\n", 33333.0); printf("\n");
printf("(\"%%#'.0f\", 33333.0) : "); printf("'%#'.0f'\n", 33333.0); printf("\n");
printf("(\"%%'#'.0f\", 33333.0) : "); printf("'%'#'.0f'\n", 33333.0); printf("\n");
printf("(\"%%'08i\", 33333) : "); printf("'%'08i'\n", 33333); printf("\n");
printf("(\"%%0'8i\", 33333) : "); printf("'%0'8i'\n", 33333); printf("\n");
printf("(\"%%'0'8i\", 33333) : "); printf("'%'0'8i'\n", 33333); printf("\n");
printf("(\"%%'-8i\", 33333) : "); printf("'%'-8i'\n", 33333); printf("\n");
printf("(\"%%-'8i\", 33333) : "); printf("'%-'8i'\n", 33333); printf("\n");
printf("(\"%%'-'8i\", 33333) : "); printf("'%'-'8i'\n", 33333); printf("\n");
printf("(\"%%'+i\", 33333) : "); printf("'%'+i'\n", 33333); printf("\n");
printf("(\"%%+'i\", 33333) : "); printf("'%+'i'\n", 33333); printf("\n");
printf("(\"%%'+'i\", 33333) : "); printf("'%'+'i'\n", 33333); printf("\n");
printf("(\"%%' i\", 33333) : "); printf("'%' i'\n", 33333); printf("\n");
printf("(\"%% 'i\", 33333) : "); printf("'% 'i'\n", 33333); printf("\n");
printf("(\"%%' 'i\", 33333) : "); printf("'%' 'i'\n", 33333); printf("\n");
printf("- repetition with ' ' -------------------------\n");
printf("- '+' and ' ' not compatible ------------------\n");
printf("- rau -----------------------------------------\n\n");
printf("(\"%% i\", 33333) : "); printf("'% i'\n", 33333); printf("\n");
printf("(\"%% #.0f\", 33333.0) : "); printf("'% #.0f'\n", 33333.0); printf("\n");
printf("(\"%%# .0f\", 33333.0) : "); printf("'%# .0f'\n", 33333.0); printf("\n");
printf("(\"%% # .0f\", 33333.0) : "); printf("'% # .0f'\n", 33333.0); printf("\n");
printf("(\"%% 08i\", 33333) : "); printf("'% 08i'\n", 33333); printf("\n");
printf("(\"%%0 8i\", 33333) : "); printf("'%0 8i'\n", 33333); printf("\n");
printf("(\"%% 0 8i\", 33333) : "); printf("'% 0 8i'\n", 33333); printf("\n");
printf("(\"%% -8i\", 33333) : "); printf("'% -8i'\n", 33333); printf("\n");
printf("(\"%%- 8i\", 33333) : "); printf("'%- 8i'\n", 33333); printf("\n");
printf("(\"%% - 8i\", 33333) : "); printf("'% - 8i'\n", 33333); printf("\n");
printf("(\"%% 'i\", 33333) : "); printf("'% 'i'\n", 33333); printf("\n");
printf("(\"%%' i\", 33333) : "); printf("'%' i'\n", 33333); printf("\n");
printf("(\"%% ' i\", 33333) : "); printf("'% ' i'\n", 33333); printf("\n");
printf("- repetition with '-' -------------------------\n");
printf("- '0' and '-' not compatible ------------------\n");
printf("- rau -----------------------------------------\n\n");
printf("(\"%%----i\", 33333) : "); printf("'%----i'\n", 33333); printf("\n");
printf("(\"%%-#.0f\", 33333.0) : "); printf("'%-#.0f'\n", 33333.0); printf("\n");
printf("(\"%%#-.0f\", 33333.0) : "); printf("'%#-.0f'\n", 33333.0); printf("\n");
printf("(\"%%-#-.0f\", 33333.0) : "); printf("'%-#-.0f'\n", 33333.0); printf("\n");
printf("(\"%%-+8i\", 33333) : "); printf("'%-+8i'\n", 33333); printf("\n");
printf("(\"%%+-8i\", 33333) : "); printf("'%+-8i'\n", 33333); printf("\n");
printf("(\"%%-+-8i\", 33333) : "); printf("'%-+-8i'\n", 33333); printf("\n");
printf("(\"%%- i\", 33333) : "); printf("'%- i'\n", 33333); printf("\n");
printf("(\"%% -i\", 33333) : "); printf("'% -i'\n", 33333); printf("\n");
printf("(\"%%- -i\", 33333) : "); printf("'%- -i'\n", 33333); printf("\n");
printf("(\"%%-'i\", 33333) : "); printf("'%-'i'\n", 33333); printf("\n");
printf("(\"%%'-i\", 33333) : "); printf("'%'-i'\n", 33333); printf("\n");
printf("(\"%%-'-i\", 33333) : "); printf("'%-'-i'\n", 33333); printf("\n");
printf("- repetition with '+' -------------------------\n");
printf("- '+' and ' ' not compatible ------------------\n");
printf("- rau -----------------------------------------\n\n");
printf("(\"%%++++i\", 33333) : "); printf("'%++++i'\n", 33333); printf("\n");
printf("(\"%%+#.0f\", 33333.0) : "); printf("'%+#.0f'\n", 33333.0); printf("\n");
printf("(\"%%#+.0f\", 33333.0) : "); printf("'%#+.0f'\n", 33333.0); printf("\n");
printf("(\"%%+#+.0f\", 33333.0) : "); printf("'%+#+.0f'\n", 33333.0); printf("\n");
printf("(\"%%+08i\", 33333) : "); printf("'%+08i'\n", 33333); printf("\n");
printf("(\"%%0+8i\", 33333) : "); printf("'%0+8i'\n", 33333); printf("\n");
printf("(\"%%+0+8i\", 33333) : "); printf("'%+0+8i'\n", 33333); printf("\n");
printf("(\"%%+-8i\", 33333) : "); printf("'%+-8i'\n", 33333); printf("\n");
printf("(\"%%-+8i\", 33333) : "); printf("'%-+8i'\n", 33333); printf("\n");
printf("(\"%%+-+8i\", 33333) : "); printf("'%+-+8i'\n", 33333); printf("\n");
printf("(\"%%+'i\", 33333) : "); printf("'%+'i'\n", 33333); printf("\n");
printf("(\"%%'+i\", 33333) : "); printf("'%'+i'\n", 33333); printf("\n");
printf("(\"%%+'+i\", 33333) : "); printf("'%+'+i'\n", 33333); printf("\n");
printf("- repetition with '#' -------------------------\n");
printf("- rau -----------------------------------------\n\n");
printf("(\"%%####f\", 33333.0) : "); printf("'%####f'\n", 33333.0); printf("\n");
printf("(\"%%#+.0f\", 33333.0) : "); printf("'%#+.0f'\n", 33333.0); printf("\n");
printf("(\"%%+#.0f\", 33333.0) : "); printf("'%+#.0f'\n", 33333.0); printf("\n");
printf("(\"%%#+#.0f\", 33333.0) : "); printf("'%#+#.0f'\n", 33333.0); printf("\n");
printf("(\"%%#08f\", 33333.0) : "); printf("'%#08f'\n", 33333.0); printf("\n");
printf("(\"%%0#8f\", 33333.0) : "); printf("'%0#8f'\n", 33333.0); printf("\n");
printf("(\"%%#0#8f\", 33333.0) : "); printf("'%#0#8f'\n", 33333.0); printf("\n");
printf("(\"%%#-8f\", 33333.0) : "); printf("'%#-8f'\n", 33333.0); printf("\n");
printf("(\"%%-#8f\", 33333.0) : "); printf("'%-#8f'\n", 33333.0); printf("\n");
printf("(\"%%#-#8f\", 33333.0) : "); printf("'%#-#8f'\n", 33333.0); printf("\n");
printf("(\"%%#'f\", 33333.0) : "); printf("'%#'f'\n", 33333.0); printf("\n");
printf("(\"%%'#f\", 33333.0) : "); printf("'%'#f'\n", 33333.0); printf("\n");
printf("(\"%%#'#f\", 33333.0) : "); printf("'%#'#f'\n", 33333.0); printf("\n");
printf("(\"%%# f\", 33333.0) : "); printf("'%# f'\n", 33333.0); printf("\n");
printf("(\"%% #f\", 33333.0) : "); printf("'% #f'\n", 33333.0); printf("\n");
printf("(\"%%# #f\", 33333.0) : "); printf("'%# #f'\n", 33333.0); printf("\n");
printf("- repetition with '0' -------------------------\n");
printf("- '0' and '-' not compatible ------------------\n");
printf("- rau -----------------------------------------\n\n");
printf("(\"%%0000i\", 33333) : "); printf("'%0000i'\n", 33333); printf("\n");
printf("(\"%%0#.0f\", 33333.0) : "); printf("'%0#.0f'\n", 33333.0); printf("\n");
printf("(\"%%#0.0f\", 33333.0) : "); printf("'%#0.0f'\n", 33333.0); printf("\n");
printf("(\"%%0#0.0f\", 33333.0) : "); printf("'%0#0.0f'\n", 33333.0); printf("\n");
printf("(\"%%0+8i\", 33333) : "); printf("'%0+8i'\n", 33333); printf("\n");
printf("(\"%%+08i\", 33333) : "); printf("'%+08i'\n", 33333); printf("\n");
printf("(\"%%0+08i\", 33333) : "); printf("'%0+08i'\n", 33333); printf("\n");
printf("(\"%%0 i\", 33333) : "); printf("'%0 i'\n", 33333); printf("\n");
printf("(\"%% 0i\", 33333) : "); printf("'% 0i'\n", 33333); printf("\n");
printf("(\"%%0 0i\", 33333) : "); printf("'%0 0i'\n", 33333); printf("\n");
printf("(\"%%0'i\", 33333) : "); printf("'%0'i'\n", 33333); printf("\n");
printf("(\"%%'0i\", 33333) : "); printf("'%'0i'\n", 33333); printf("\n");
printf("(\"%%0'0i\", 33333) : "); printf("'%0'0i'\n", 33333); printf("\n");
// printf("-----------------------------------------------\n");
// printf("- BONUS -\n");
@@ -334,6 +548,13 @@ int main(void)
// printf("(\"%%2$i-%%i\",3,2) ft : "); ft_printf("'%2$i-%i'\n", 3, 2);
printf("(\"%%2$i-%%i\",3,2) : ");/* printf("'%2$i-%i'", 3, 2);*/ printf(" cannot mix positioned and non-positioned args\n\n");
// printf("(\"%% +i\", 33 : "); ft_printf("'% +i'\n", 33);
printf("(\"%% +i\", 33 : ");/* printf("'% +i'\n", 33);*/ printf(" flag ' ' is ignored when '+' is present\n\n");
// printf("(\"%%-0i\", 33 : "); ft_printf("'%-+i'\n", 33);
printf("(\"%%-0i\", 33 : ");/* printf("'%-0i'\n", 33);*/ printf(" flag '0' is ignored when '-' is present\n\n");
return (0);
}