Iam Trying to implement a basic text editor in c++. I've used a doubly linked list for storing the typed characters in a line and have implemented another linked list (No 2)to store many such lines for a document...
When i try to save the file using list No2,i find that the stored file contains junk...but the underlying retrieval of data from the list seems to work fine enough...can someone help me on this....
The code i implemented for the save method is as follows
void lines::save()//save is a method of class lines(list 2)
{
dnode *ptr2;//ptr2 is a node class object(pointer) for line list
dlnode *ptr1;//ptr1 is a node class object for lines list(list 2)
char x;
cout<<"ENTER FILE NAME TO SAVE:\n";
cin>>fname;
strcat(fname,".txt");
fstream buf(fname,ios :: out);
for(ptr1=start->getNext();ptr1;ptr1=ptr1->getNext())
{
for(ptr2=ptr1->getLineStart()->getNext();ptr2;ptr2=ptr2->getNext())
//method getLineStart is in dlnode and method getNext is in dnode.This is to get starting location of each line node from class dnode.ptr2=ptr2->getNext() moves to the next node location.
{
buf<<ptr2->getChar();
}
}
buf.close();
}
Thanks.