Thread: store data from ifstream and store in link list

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    141

    store data from ifstream and store in link list

    hi everyone, i have no idea on how to store values into a link list which data is from IFSTREAM

    for example..the data.txt as below
    192.149.089.061
    100.001.004.031
    034.056.078.012
    192.149.089.061
    100.001.004.031
    192.149.089.061
    111.022.033.004
    192.149.089.061
    111.022.033.004
    111.022.033.004

    and i want to stored it in link list .. how can i make it ???

    this is my main code

    Code:
    int main()
    {
        IPlist ip;  
    	ifstream myFile;           //input file stream variable
        char filename[40];         //filename is used to store the name of the input file
        
         
        cout<<"Enter name of file : ";
        cin>>filename;
        myFile.open(filename); //open the input file 
        
        while(!myFile) //if open did not fail
        {
            myFile.clear();
            cout << "Invalid file name" << endl;
            cout << "Enter name of file : " ; //read the name of the input file
            cin >> filename;
            myFile.open(filename); //open the input file 
        }
        while(myFile>> filename)
        {
            cout << filename << endl;
        }
        
        if (ip.empty())
        
        
        
        system("pause");
        return 0;
    }
    any help and idea will be really appreciated ... thank you

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Replace cout << filename << endl with code that adds the data to the list.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    yap i got tat.. erm,, can you check this error for me please..i have two version....
    Code:
    void IPlist::updateCount(string address)
    // precondition : address is in list
    // postcondition : the count of node with address has been incremented
    {
        node *tmp = list;
        tmp->count = 0;
        while(tmp != NULL && isPresent(address) )
        {
            tmp->count++;
            tmp = tmp->link;
        }
    }
    Code:
    void IPlist::updateCount(string address)
    // precondition : address is in list
    // postcondition : the count of node with address has been incremented
    {
        node *newList = new node;
        newList->IPaddress = address;
        newList->count = 0;
        //newList->link = NULL;
        
        if( isPresent(address) )
        {
            newList->count++;
            newList = newList->link;
        }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using class to retrieve and store data
    By FoodDude in forum C++ Programming
    Replies: 9
    Last Post: 08-19-2005, 07:50 AM
  2. Replies: 26
    Last Post: 06-15-2005, 02:38 PM
  3. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 09:01 AM
  4. Help!!!!!!!!
    By Shy_girl_311 in forum C++ Programming
    Replies: 3
    Last Post: 10-10-2001, 02:22 PM