I apologize for the words in spanish, but basicly what im trying to do in this funtion is to create a new set. But when i create a double pointer one of the parameters I pass to the function is being modified, I really dont give any idea of whats wrong. Please any help or comment.
the problem is that parametr is writen for the user so im not sure if i can declare it as const char* elementos.
The fact is that this function works when i use independetly but when i try to use from another function it doesnt work, the line 12 modifies elementos
this is the other function
1 2 3 4 5 6 7 8 9 10 11 12
void CAnalizador::SetUnion(char* Nuevo, char* A, char* B)
{
char* p = Union(A,B);
int num = 0;
while(*p != 0)
{
p++;
num++;
}
p-=num;
Set(Nuevo,p,num);
}
i have debugged it all step by step and is when i call CAnalizador::Set from CAnalizador::SetUnion on the conjunTemp = new char*[comas+1]; that elementos is changed.
I have seen how above that line it has the value that i need and executing it, change its value.
are u ok with this two functions or wanna see the program??
vlad: the reason that the second value of elementos is "" is tha i move myself to its last position but i think that it still have de "a,b,c,1,2,3".
im as inpresed as you i just dont know what it is.
Cire: Union returns a char* that is created inside the same function
Well, obviously it returns a char*. But does it return a char* which contains an address of something which ceases to exist when Union() returns? If it did, it would fit the symptoms perfectly.
Perhaps posting the definition of Union would be in order.
Yeah, that is what is wrong. Union goes out of scope when the function returns and the memory pointed to by the address returned is no longer valid. When the stack is modified in the later function it modifies the stuff that elementos points to (because elementos points to memory on the stack that has been recycled.)
Using containers instead of arrays is probably the simplest way to address the issue (ie return a vector or set instead of a pointer.)