So, I'm working on Binary Trees and I need to move information from one node to another one (structs). The thing is that I have this function that uses strcpy to copy the names and surnames from one node to other node (both sent as pointers) and when I try to run that part of the code in the program, it crashes.
Here is the function that copies the info (It has to copy the info from nodo2 to nodo1):
void MoverDatos(Tarbol *nodo1, Tarbol *nodo2)
{
strcpy((*nodo1)->appat, (*nodo2)->appat);
strcpy((*nodo1)->apmat, (*nodo2)->apmat);
strcpy((*nodo1)->nombre, (*nodo2)->nombre);
(*nodo1)->matr=(*nodo2)->matr;
}
As it wasn't working that way, I tried to use this one instead:
void MoverDatos(Tarbol *nodo1, Tarbol *nodo2)
{
char cad1[20];
char cad2[20];
char cad3[20];
strcpy(cad1, (*nodo2)->appat);
strcpy(cad2, (*nodo2)->apmat);
strcpy(cad3, (*nodo2)->nombre);
strcpy((*nodo1)->appat, cad1);
strcpy((*nodo1)->apmat, cad2);
strcpy((*nodo1)->nombre, cad3);
(*nodo1)->matr=(*nodo2)->matr;
}
But it didn't work either. I don't know if I'm not setting the arguments the right way or if I need to use another function, so any help or sugestion would be great. Thanks in advance.
It does compile with those arguments. I'm not getting any error message, it just crash and says that "program.exe has stopped working".
This is the struct that I'm using:
typedef struct _tdato
{
long matr;
char nombre[20];
char appat[20];
char apmat[20];
struct _tdato *sig;
struct _tdato *ant;
struct _tdato *padre=NULL;
}Tdato;
typedef Tdato *Tarbol;
The crash comes when I trie to copy a char[ ] to nodo1.