I have a file.txt
file
|i|Correo|Apellido|Nombre|
|-+------+--------+------|
|0|-a@.mx|----a---|--a---|
|1|-b@.mx|----b---|--b---|
|2|-c@.mx|----c---|--c---|
which I read with the following function
void readFILE()
{
ifstream file;
string line;
file.open(path, ios::in);
if(file.fail()) printf("Error reading\n");
while(!file.eof())
{
getline(file, line);
cout << line << endl;
}
file.close();
}
I have the problem that I can't think of a way to take each string I read as if the entire row were a string and store it in a doubly linked list.
example.
line[0] = "|i|Correo|Apellido|Nombre|";
line[2] = "|0|a@.mx |a |a |";
take each string and store it in:
struct node {
string *data;
struct node *next;
struct node *prev;
int size;
};
struct node* MakeNode(string *data)
{
struct node* newnode = (struct node*) malloc(sizeof(struct node));
newnode->prev = newnode;
newnode->data = data;
newnode->next = newnode;
newnode->size = 1;
return newnode;
}
struct node* addEnd(struct node* tail, string *data)
{
struct node* newnode = MakeNode(data);
if(tail == NULL) return newnode;
else
{
struct node* temp = tail->next;
newnode->next = temp;
newnode->prev = tail;
tail->next = newnode;
temp->prev = newnode;
tail = newnode;
return tail;
}
}
I imagine it as extracting the entire line of the file in a string, then storing that string in the data of the node and then doing operations with the nodes such as ordering.