diff options
-rw-r--r-- | libft/src/ft_strsubst.c | 2 | ||||
-rw-r--r-- | src/ft_p_lcom_next.c | 12 |
2 files changed, 6 insertions, 8 deletions
diff --git a/libft/src/ft_strsubst.c b/libft/src/ft_strsubst.c index dd89917..57e0ac8 100644 --- a/libft/src/ft_strsubst.c +++ b/libft/src/ft_strsubst.c @@ -30,7 +30,7 @@ char ft_memcpy(nstr + (ptr - str + ft_strlen(subst)), str + (ptr - str + ft_strlen(pattern)), ft_strlen(str + (ptr - str + ft_strlen(pattern)))); - nstr[nlen + 1] = '\0'; + nstr[nlen] = '\0'; ft_memdel((void*)&str); return (nstr); } diff --git a/src/ft_p_lcom_next.c b/src/ft_p_lcom_next.c index e025f96..34c0d2c 100644 --- a/src/ft_p_lcom_next.c +++ b/src/ft_p_lcom_next.c @@ -24,6 +24,7 @@ char /* TODO: norme */ char **p_words; char *s_varname; + char *varval; int64_t i; size_t varlen; @@ -31,20 +32,17 @@ char varlen = 0; while (*p_words) { - while (varlen < ft_strlen(*p_words) && - (i = ft_strlchr((*p_words) + varlen, '$'))) + while ((i = ft_strlchr(*p_words, '$')) != -1) { - ft_printf("%ld|||\n", i); - if (i == -1) - break ; varlen = i + 1; while ((*p_words)[varlen] != '\0' && (*p_words)[varlen] != '$') varlen += 1; - varlen -= 1; if (!(s_varname = ft_substr(*p_words, (uint32_t)i, varlen))) return (NULL); - ft_printf("{%s} | {%s}\n", s_varname, ft_subst_var_value(s_varname, msh)); + varval = ft_subst_var_value(s_varname, msh); + *p_words = ft_strsubst(*p_words, s_varname, varval); ft_memdel((void*)&s_varname); + ft_memdel((void*)&varval); varlen += 1; } p_words += 1; |