I am trying to parse the data from a file with certain structure. this data will be written into a double linked list (Next and prev) i have already made the function to read the data from the file and put into a temporal list, but when i try to pass it to the final list, somehow the data is missing. I think this is because of a bad linking between the fields of the list, but i cannot find the exact linking problem, the code is this:
void LeerArchivo (Persona **p, string doc){
int n = 0;
Persona *Aux = *p;
Persona *t = new Persona;
Fecha *f = new Fecha;
Vehiculo *v = new Vehiculo;
ifstream Archivo(doc.c_str()); // Abro el archivo en modo lectura
if (Archivo)
{
while (!(Archivo.eof())){ // Mientras archivo no llegue al final del documento (end of file) ejecuta las instrucciones
n = 0;
Archivo >> t->Cedula; // Paso la primera linea de archivo al campo cedula del primer registro persona
Archivo >> t->Nombre;
Archivo >> t->Apellido;
Archivo >> f->Dia;
Archivo >> f->Mes;
Archivo >> f->Annio;
t->Nacimiento = f;
Archivo >> n; // Esto sera un integer 1 o 0 contenido en el archivo que indica si la persona tiene carro o no
if (n){
Archivo >> v->Placa;
Archivo >> v->Marca;
Archivo >> v->Modelo;
Archivo >> v->Color;
Archivo >> v->Annio;
v->Propietario = t;
t->Carro = v;
}
else
t->Carro = NULL;
if(Aux){
t->Siguiente = NULL;
(Aux)->Siguiente = t;
t->Anterior = Aux;
Aux = t;
Aux = (Aux)->Siguiente;
}
else{
Aux = t;
t->Siguiente = NULL;
t->Anterior = NULL;
};
};
}
else
{
cout << "El archivo " << doc << " no existe" << endl;
}
};
When the parse is finished, the only data left in the list is the last register read from the file, so i am sure the data is being overwritten instead of being linked.
In the linking part i have also tried this pieces of code
if(Aux){
(*p)->Siguiente = NULL;
(*p)->Siguiente = t;
t->Anterior = *p;
*p = t;
*p = (*p)->Siguiente;
}
else{
*p = t;
t->Siguiente = NULL;
t->Anterior = NULL;
};
And this other
if(Aux){
(*p)->Siguiente = NULL;
(*p)->Siguiente = t;
t->Anterior = *p;
*p = t;
}
else{
*p = t;
t->Siguiente = NULL;
t->Anterior = NULL;
};
*p = (*p)->Siguiente;
I will appreciate any suggestions about the code, thank you :D