Thread: file i/o -linked list

  1. #1

    Question file i/o -linked list

    I am trying to insert data from a file into a struct and then a singly linked list. The file has 9 rows of data per entry and 10 entries. Each entry contains 5 char rows, 1 double and 3 ints. I am missing something here, the printed list skips over several rows and only contains 2 of the 10 entries. I believe the problem lies in the struct portion of the code. Please give me some insight and direction. I've attached the file since it is to big to post here.

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    The >> operator will leave a '\n' in the input buffer, so everytime you use it before getline you'll have to remove the '\n'. Your file read should be something like this -

    			inFile >> temp.price;
    			inFile >> temp.copyrightDate;
    			inFile >> temp.quantity;
    			inFile >> temp.status;
    			readInv(&head, temp);//call function to fill linked-lists

  3. #3
    Registered User
    Join Date
    Dec 2001


    zen, I cannot thank you enough! It worked like a charm and that's a beautiful thing. Again, thanks so much, you are number one in my book, thanks and thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked List Not Saving Value as Int
    By bar338 in forum C Programming
    Replies: 4
    Last Post: 05-04-2009, 07:53 PM
  2. help! Placement of nodes in a Linked List
    By lostmyshadow in forum C Programming
    Replies: 6
    Last Post: 12-17-2007, 01:21 PM
  3. Replies: 5
    Last Post: 11-04-2006, 06:39 PM
  4. help with linked lists and file i/o
    By Mazer in forum C++ Programming
    Replies: 1
    Last Post: 10-21-2003, 01:59 PM
  5. Linked list with two class types within template.
    By SilasP in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2002, 06:13 AM