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";
    fstream buf(fname,ios :: out);
//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.


Edited 3 Years Ago by Dani: Formatting fixed

I can't really help much without seeing most of the code, but below won't work with filenames that contain spaces. and hopefully fname is defined to be max size for your operating system so that it can contain full path to the file. Id suggest you use std::string for the filename instead of C-style character array buffer, and use getline() instead of cin's insertion operator.


std::string fname;
fname += ".txt";
fstream buf(fname.c_str(),ios :: out);

I have Used Turbo C++ For My Text Editor.

I hope you are not using that ancient compiler in an attempt to learn the c++ language -- if you are then you will be learning the wrong language. Its like reading Shakespear to learn modern-day English, not very useful. Get one of the free c++ modern compilers, such as Dev-C++

This article has been dead for over six months. Start a new discussion instead.