0

I have been trying to read back the information from a file that i created. I get all the information i need out of the file but now all i want is to use the display function from the linklist to get that information. I would like it if the function could get the size of the node from the file and print it back to the user but for the life of me i cant figure out how to do it. Here is the code i have and what i have been trying to do.

id.open("incidentID.txt", ios::in|ios::app|ios::ate);
            if (id.is_open())
            {
                cout<<endl;
                cout<<"Enter type: "<<endl;
                cin>>type;
                a.settype(type);
                cout<<"Enter description: "<<endl;
                cin>>description;
                a.setdescription(description);
                cout<<"Enter Counter: "<<endl;
                cin>>counter;
                a.setcounter(counter);
                cout<<"Enter Priority: "<<endl;
                cin>>priority;
                a.setpriority(priority);
                //a.display();
                b.addInode(a.getincidentid(), a.gettype(), a.getdescription(), a.getcounter(), a.getpriority());
                id<<a.getincidentid()<<endl;
                id<<a.gettype()<<endl;
                id<<a.getdescription()<<endl;
                id<<a.getcounter()<<endl;
                id<<a.getpriority()<<endl;

                a.setincidentid(a.getincidentid()+1);
                    break;
            }
            else
            {
                cout<<"File was not found"<<endl;
            }
            id.close();
            break;

This inserts the information into the file

id.open("incidentID.txt", ios::out|ios::in);
    if (id.is_open())
    {
        cout<<a.getincidentid()<<endl;
        cout<<"Please enter the information you want to search for: "<<endl;
        cin>>tet;
        while (!id.eof())
        {
            getline(id, typee);
            file[i]=typee;
            cout<<file[i]<<endl;
            i++;
        }

This part reads the information from the file and store it into a string array. I have a display function from the linklist.

    void displayInode(int key)  //displays the content of a specific node when searched for
    {
        incident *temp=head;
        while(temp!=NULL)
        {
            if(temp->getincidentid()==key)
            {
                temp->display();
                return;
            }
            temp=temp->getNextincident();
        }
        cout<<"this client record does not exist"<<endl;
    }

I want this display to pull the information from the file and print it back to the user. The user should enter the incidentid they want to search for and display it. How would i use this to read from the file and print of the information of just that node. Thanks for any help

Edited by slygoth

2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by Ancient Dragon
0

You have to read the file just like it was written, each node occupies 5 lines in the file. So in the function that reads the file it has to read all 5 lines in order to find the id numbers

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.