Thread: file i/o -linked list

  1. #1
    Unregistered
    Guest

    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
    Posts
    1,007
    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 -

    Code:
    			getline(inFile,temp.lName,'\n');
    			getline(inFile,temp.fName,'\n');
    			inFile >> temp.price;
    			inFile.ignore(1);
    			getline(inFile,temp.publisher,'\n');
    			getline(inFile,temp.isbn,'\n');
    			inFile >> temp.copyrightDate;
    			inFile >> temp.quantity;
    			inFile >> temp.status;
    			readInv(&head, temp);//call function to fill linked-lists
    			inFile.ignore(1);
    zen

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    4

    Talking

    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