| | |
Hash Table display problem
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Oct 2006
Posts: 17
Reputation:
Solved Threads: 0
I wrote a hash table that takes a char as a key and for a test I am using a string for my value. It uses a linked list. But I am having a problem displaying the value. I have a function that displays the key correctly but the value is displayed as garbage. I am prety sure it is this one method that is causing it to display incorrectly but it complies and runs fine, i am just not sure why this does not work. Here is the method I think is not working and I am attaching the entire sample program as a txt file if someonecan take a look. I a little stuck on this.
Here is my Display Function and it calls this function so I am assuming that for some reason the data is not bein copied correctly.
Thanks
C++ Syntax (Toggle Plain Text)
bool Hashtable::get(char *key, string value) { METADATA* temp = find(key); if(temp == NULL) { value = ""; return false; } else { value = temp->value; return true; } }
Here is my Display Function and it calls this function so I am assuming that for some reason the data is not bein copied correctly.
C++ Syntax (Toggle Plain Text)
void displayAll(Hashtable *hashtable) { char key[SIZE_KEY]; char value[SIZE_VALUE]; cout<< "\nCurrent nodes in hashtable: " << endl; hashtable->initIterator(); while(hashtable->hasNext()) { hashtable->getNextKey(key); hashtable->get(key, value); cout << "key: " << key << "\tvalue : " << value << endl; } }
Last edited by blazted; Jun 1st, 2007 at 4:15 pm.
value is an array. When you pass it as the second argument to get, it acts as the initializer for the std::string parameter. You've lost your reference, and any changes to the parameter will not be reflected back in displayAll. Change value to a string and pass it by reference to get.
I'm here to prove you wrong.
![]() |
Similar Threads
- Hash Table template implementation help (C++)
- Help appreciated on a display problem (Windows 95 / 98 / Me)
- Bright green display problem (Windows NT / 2000 / XP)
- Pass XML file contents to a hash table. (Java)
- compile error-chained hash table c++ (C++)
Other Threads in the C++ Forum
- Previous Thread: help if possible (asap)
- Next Thread: gnu/gcc
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion count database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive return sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






