Thread: Trouble with linked list

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    54

    Trouble with linked list

    *Edit* Ignore this portion, current issue is at post 5.



    I'm attempting to extract info from a text file and load it into a linked list. The problem I'm running into is that I'm trying to only have 3 members for the struct, but when I try to read in the name, I'm having to split it up due to a white space in between.

    The text file is formatted as such:

    Last_name, First_name
    ID_Number
    Address

    How do I get the program to read in "Doe, John" as name. I want it to store the information just like it's read, i.e. I don't want it to remove the white space, rather just continue reading until it reaches a new line.

    I'll also have the same problem when it gets to address.

    Also, when I get there, I'm going to want to be able to search within the linked list by a particular member, say, name. But I'm going to only want to search using either first_name or last_name. I assume there will be a way for me to just search through the member type, at which point I'll have to tell it to stop searching when it reaches ',' -- yes?

    Here's what I've got so far:

    Code:
    struct node
    {
         char name[30];
         char lastName[30];
         int ID;
         char address[50];
         node *next;
    };
    
    int main(int argc, char *argv[])
    {
        ifstream inFile ("A1.txt");
        
        node *root;
        root = new node;
        root->next = 0;
        
        inFile >> root->name;
        inFile >> root->lastName;
        inFile >> root->ID;
        inFile >> root->address;
        
        cout << root->name     << endl
             << root->lastName << endl
             << root->ID       << endl
             << root->address  << endl;
    
    
        
        inFile.close();
    Last edited by mikeman; 01-21-2010 at 03:40 PM. Reason: updating

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 10:01 AM
  2. Problem with linked list ADT and incomplete structure
    By prawntoast in forum C Programming
    Replies: 1
    Last Post: 04-30-2005, 01:29 AM
  3. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM
  4. Template Class for Linked List
    By pecymanski in forum C++ Programming
    Replies: 2
    Last Post: 12-04-2001, 09:07 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM