reading files into linked lists

This is a discussion on reading files into linked lists within the C++ Programming forums, part of the General Programming Boards category; First off, this is for homework and I mearly want a shove in the right direction. If its with a ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    11

    reading files into linked lists

    First off, this is for homework and I mearly want a shove in the right direction. If its with a nudge or a dump truck makes no nevermind to me.

    What I want to do is have a class member function that reads a file into a doubly linked list. I am curious on a few points.

    1. Should my function parameter look something like this?
    void readFile (const ifstream & inData); if not, please advise

    2. For input of this nature, should it be arranged in any specific way? If, for example, each node has a string and an integer.

    3. Function will replace current list if one exists, is there anything I need to be careful of?

    If there is any tutorials that could help, I would be appreciative.

    I thank you all in advance for taking a look at my problem

    Meeloff

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    1) no one can answer that question with information given
    2) should WHAT be arranged in any specific order?
    3) memory leaks
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,806
    Quote Originally Posted by meeloff
    1. Should my function parameter look something like this?
    void readFile (const ifstream & inData); if not, please advise
    I'd remove the const from that but the rest seems fine.

    Quote Originally Posted by meeloff
    2. For input of this nature, should it be arranged in any specific way? If, for example, each node has a string and an integer.
    You can have the file contain the data in any specific order you wish. It could be all on a single line or you can have the pieces on seperate lines one after the other... it all depends on you.

    Quote Originally Posted by meeloff
    3. Function will replace current list if one exists, is there anything I need to be careful of?
    Every time you call this readFile function, just check the existing list to see if it is empty or not. If not, then delete the existing list prior to reading input from the file.

    If you can use it, then I would strongly suggest using the STL list container to store your data... unless the point of this exercise is geared towards your implementing a linked list and not simply the use of a linked list. Using the STL list container will allow you to focus on the implemention of the remaining portions of your program.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  2. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  3. Linked Lists tutorial
    By BunkFace in forum C Programming
    Replies: 2
    Last Post: 01-04-2006, 03:59 AM
  4. Reading files in a directory
    By roktsyntst in forum Windows Programming
    Replies: 5
    Last Post: 02-07-2003, 10:04 AM
  5. Linked Lists and Inheritance
    By mattyneedshelp! in forum C++ Programming
    Replies: 6
    Last Post: 02-01-2003, 07:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21