J
Javier
Hi All
I've the defined the following structure:
struct PhoneNumbers
{
char *numero;
struct PhoneNumbers *next;
};
PhoneNumbers *phones = NULL;
PhoneNumbers *primero = NULL;
PhoneNumbers *prov = NULL;
Then I read a text file and fill the linked list with data:
while (! examplefile.eof() ) {
examplefile.getline (buffer,100);
if (primero == NULL) {
primero = new PhoneNumbers;
phones = primero;
phones->next = NULL;
} else {
phones->next = new PhoneNumbers;
phones = phones->next;
phones->next = NULL;
}
phones->numero = buffer;
}
Everything goes well till now but...
After this, I want to verify if my linked list was filled correctly with
data. Then I did:
cout << "\nPrimero " << primero;
printf("\n-----------------\n");
phones = primero;
while (phones != NULL) {
cout << "Ptr: " << phones << " Numero: " << phones->numero << endl;
phones = phones->next;
}
But I see only the last data read repeated in all nodes !!!
I'm new with C++ and I couldn't find my mistake... I don't know if the
error comes from filling procedure or when I try to show data.
Any help appreciated.
Javier
I've the defined the following structure:
struct PhoneNumbers
{
char *numero;
struct PhoneNumbers *next;
};
PhoneNumbers *phones = NULL;
PhoneNumbers *primero = NULL;
PhoneNumbers *prov = NULL;
Then I read a text file and fill the linked list with data:
while (! examplefile.eof() ) {
examplefile.getline (buffer,100);
if (primero == NULL) {
primero = new PhoneNumbers;
phones = primero;
phones->next = NULL;
} else {
phones->next = new PhoneNumbers;
phones = phones->next;
phones->next = NULL;
}
phones->numero = buffer;
}
Everything goes well till now but...
After this, I want to verify if my linked list was filled correctly with
data. Then I did:
cout << "\nPrimero " << primero;
printf("\n-----------------\n");
phones = primero;
while (phones != NULL) {
cout << "Ptr: " << phones << " Numero: " << phones->numero << endl;
phones = phones->next;
}
But I see only the last data read repeated in all nodes !!!
I'm new with C++ and I couldn't find my mistake... I don't know if the
error comes from filling procedure or when I try to show data.
Any help appreciated.
Javier