typedef struct element element;
struct element{
dado_t str;
elemento* preview;
elemento* next;
};
typedef struct lista2 lista2;
struct lista2{
elemento* primeiro;
elemento* ultimo;
elemento* corrente;
};
void caller(lista2* l){
char *s = l->corrente->str;
char *s2 = l->corrente->next->str;
my_func(&s, &s2);
}
void my_func(char **s, char**s2){
size_t len = strlen(*s);
size_t len2 = strlen(*s2);
char *w = *s;
char *tmp = realloc(w, len + len2 + 1); //PROBLEM HERE
if(tmp != NULL)
*s = tmp;
else
*s = NULL;
strcat(*s, *s2);
}
When I run my code(before realloc()
):
*w = "I Like Coffe"
with memory adress:0x605050
*s = "I Like Coffe"
with memory adress:0x605050
l->corrente->str = "I Like Coffe"
with memory adress:0x605050
All good so far.
Now status after realloc
(Before the assign *s = tmp)
:
*w = ""
with memory adress:0x605050
*s = ""
with memory adress:0x605050
l->corrente->str = ""
with memory adress:0x605050
Still ok, right ? Now what I get after *s = tmp
:
*w = ""
with memory adress:0x605050
*s = "I Like Coffe"
with memory adress:0x605160
CHANGEDl->corrente->str = ""
with memory adress:0x605050
What I need:
1) Change l->corrente->str
value in my_func()
;
2) Or somehow, change *s
value to the new value after strcat. And keep l->corrente->str
the same.