| | |
Hash Table display problem
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 application array based binary bitmap c# c++ c/c++ char class classes code coding compile compression console conversion count cpm delete deploy deque desktop developer dialog directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer introductory java lib linkedlist linkednodes linker loop looping loops map math matrix memory multiple news node numbertoword output parameter pointer problem program programming project python random read recursion reference rpg security sorting string strings temperature template test text text-file tree url variable vector video whyisthiscodecausingsegmentationfault win32 windows winsock wordfrequency wxwidgets






