diff --git a/ft_printf b/ft_printf index 32548bc..0500db6 100755 Binary files a/ft_printf and b/ft_printf differ diff --git a/ft_printf.c b/ft_printf.c index 22b0dbc..c343d12 100644 --- a/ft_printf.c +++ b/ft_printf.c @@ -91,9 +91,8 @@ char *ft_width(char *s, char *print, char *type) int i; ft_putstr("[");ft_putstr(s);ft_putstr("|"); - while (ft_strchr("%#- +'0.", *s)) + while (*s != '\0' && ft_strchr("%#- +'0.", *s)) s++; - ft_putstr(s);ft_putstr("|"); i = ft_atoi(s); (void)type; ft_putnbr(i);ft_putstr("]"); @@ -131,9 +130,7 @@ char *ft_width(char *s, char *print, char *type) char *ft_flag_transform(char *s, char *print, char *type) { - ft_putstr(s);ft_putstr("|"); print = ft_precision(s, print, type); - ft_putstr(s);ft_putstr("|"); print = ft_width(s, print, type); // if ((i = flag_w(s))) // { diff --git a/main.c b/main.c index 365b1d7..a8347a7 100644 --- a/main.c +++ b/main.c @@ -135,6 +135,22 @@ int main(int ac, char **av) ft_printf("'%.s'\n\n", "string"); printf("'%.7i'\n", -123456); ft_printf("'%.7i'\n\n", -123456); + +// #include +// ft_printf("Hi file\n"); +// int out = open("out.txt", O_WRONLY); +// int save = dup(1); +// dup2(out, 1); +// ft_printf("Ho fole\n"); +// dup2(save, 1); +// ft_printf("Ha fale\n"); +// dup2(out, 1); +// ft_printf("Hu fule\n"); +// dup2(save, 1); +// ft_printf("He fele\n"); +// close(save); +// close(out); + } /* ////////////////////////////////////////////////////////////////// */ diff --git a/out.txt b/out.txt new file mode 100644 index 0000000..4444a8e --- /dev/null +++ b/out.txt @@ -0,0 +1,2 @@ +Ho fole +Hu fule diff --git a/test.c b/test.c deleted file mode 100644 index bf803dd..0000000 --- a/test.c +++ /dev/null @@ -1,60 +0,0 @@ -#include - -//int ft_printf(char *string, ...) -//{ -// va_list ap; -// int d; -// char c; -// char *s; -// -// va_start(ap, string); -// while (*string != '\0') -// { -// if (*string == 's') -// s = va_arg(ap, char *); -// if (*string == 'd') -// d = va_arg(ap, int); -// if (*string == 'c') -// c = va_arg(ap, int); -// string++; -// } -// va_end(ap); -// return (0); -//} - -char *ft_strchr(const char *s, int c) -{ - int i; - int j; - - i = 0; - j = -1; - while (s[i]) - i++; - while (++j < i + 1) - if (s[j] == c) - return ((char *)s + j); - return (NULL); -} - -int main(void) -{ - char *s = "csd"; - char *str = "bravo"; - char c = 'p'; - int i = 9; - -// ft_printf(s, c, str, i); - char *test1; - char *test2; - test1 = "truc%muche"; - test1 = strdup(test1); - test2 = ft_strchr(test1,'%'); - if (test2) - test2[0] = '\0'; - printf("%s", test2); - test1[6] = 'g'; - if (test2) - printf(" - %s - %i - %s\n", test2 + 1, test2[0], test1); - return (0); -}