simple probloem

This is a discussion on simple probloem within the C++ Programming forums, part of the General Programming Boards category; Hello everyone,i have a simple regarding doubly linked list.I have two doubly linked list in which data of string type ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    33

    simple probloem

    Hello everyone,i have a simple regarding doubly linked list.I have two doubly linked list in which data of string type is stored.I gave to just check that whether the two data ae same or not?I have tried by
    Code:
    temp = head;//head of list 1
    temp1 = head1;//head of list 2
    
    if((temp->data) == (temp1->data))
    //do something
    but this is not working on string type.I have tried it on integer type and it works fine,but what is the problem with string type data??

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    When you say string, do you mean the std::string class or C strings?

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    33
    std::string class

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    Show more code. Have you tried printing temp->data and temp1->data to make sure that they are identical strings?

  5. #5
    Registered User
    Join Date
    Mar 2009
    Posts
    33
    here is my code
    Code:
    int getarticle(Node<string> A)
                  {
                      
                      
                      
                                        
                      Node<string> *temp,*temp1;
                      temp = A.gethead();  //first list
                      temp1 = M.gethead(); //second list
                     
    
               //just print list2 data
    
                    while(temp1!=NULL)
                      {
                           cout<<temp1->getData();system("pause");
                           temp1 = temp1->getNext();
                      }                        
                      
                      while(temp!=NULL)
                      {
                          if((temp->getData() == temp1->getData()) // check whther two data are same
                          {
                                   Q.enqueue(temp->getData());//if same save data in a queue
                                   temp = temp->getNext();//move temp forward to traverse the whole list1
                          }
                      }
                      
             
                  }

  6. #6
    Registered User
    Join Date
    Mar 2009
    Posts
    33
    it print the data of list2 correctly but in the checking of data,program hang up.

  7. #7
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    temp1 will be NULL when you compare the two strings, hence the segfault.

  8. #8
    Registered User
    Join Date
    Mar 2009
    Posts
    33
    thankyou sooo much.It really solved the problem.I wonder why i was not looking this one..but anyways thanx for the help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating very simple text editor using c
    By if13121 in forum C Programming
    Replies: 9
    Last Post: 10-19-2010, 06:26 PM
  2. Simple message encryption
    By Vicious in forum C++ Programming
    Replies: 10
    Last Post: 11-07-2004, 11:48 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  4. Simple simple program
    By Ryback in forum C++ Programming
    Replies: 10
    Last Post: 09-09-2004, 06:48 AM
  5. Need help with simple DAQ program
    By canada-paul in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2002, 08:52 AM

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