From f5e91534e1d612303ee0b1b0645fd1f11595759d Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Wed, 8 Jan 2020 13:42:57 +0100 Subject: [PATCH] ecriture en pseudo code de store --- ft_printf.c | 17 ++++++++------ libft | 1 - libft.c | 1 + test.c | 66 +++++++++++++++++++++++++++++++++++++---------------- 4 files changed, 57 insertions(+), 28 deletions(-) delete mode 160000 libft create mode 120000 libft.c diff --git a/ft_printf.c b/ft_printf.c index 6759121..e7564b1 100644 --- a/ft_printf.c +++ b/ft_printf.c @@ -8,17 +8,19 @@ int ft_error(int i) return (0); } -t_list *ft_store(char *str) +t_prist *ft_store(char *str) { - t_prist *arglst; - t_list *lst; + t_prist *lst; + t_prist *lstmp; char *tmp; //str = "truc: %i, machins:%s\n" + str = ft_strdup(str); + lst = NULL; while (*str != '\0') { - (*arglst) = (t_prist *)malloc(sizeof(*arglst)); - lst = ft_lstadd_back(&lst, arglst); + lstmp = lst; + (*lst) = (t_prist *)malloc(sizeof(*lst)); if (tmp = strchr(str,%)) tmp[0] = '\0' (*arglst)->str = ft_strdup(str); @@ -26,14 +28,15 @@ t_list *ft_store(char *str) if (tmp != NULL) tmp[0] = '%'; str = tmp; + lst->next = lstmp; } - return (*arglst); + return (*lst); } int ft_printf(char *string, ...) { + t_prist *lst; va_list ap; - t_list *lst; va_start(ap, string); lst = ft_store(string); diff --git a/libft b/libft deleted file mode 160000 index e9c7619..0000000 --- a/libft +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e9c7619e97420ac9dcd3c5f75b7c0105a797d280 diff --git a/libft.c b/libft.c new file mode 120000 index 0000000..5634df6 --- /dev/null +++ b/libft.c @@ -0,0 +1 @@ +../libft \ No newline at end of file diff --git a/test.c b/test.c index d0abdb9..bf803dd 100644 --- a/test.c +++ b/test.c @@ -1,25 +1,40 @@ -#include +#include -int ft_printf(char *string, ...) +//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) { - va_list ap; - int d; - char c; - char *s; + int i; + int j; - 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); + 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) @@ -29,6 +44,17 @@ int main(void) char c = 'p'; int i = 9; - ft_printf(s, c, str, i); +// 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); }