I'm trying to print the name and number of votes of an entry if it exists. But, i can't figure out how to only print the entries that exist.
Here is my code:
The problem is that if statement. I need it to only print an entry if there is an entry there, but i can't figure out what to put in that if statement.
int main(int argc, char* argv)
ifstream inFile ( argv );
if ( !inFile.is_open() )
cout << "Could not open file." << endl;
//Read names in from file. Hash them into table, or increase votes if entry is already in the table.
int flag = 0;
hashSpot = Hash(name,12);
currentEntry = name;
//If entry is not found, hash it into table.
if(flag == 0)
array1[Hash(name,12)] = new candidate;
array1[Hash(name,12)]->firstName = name;
array1[Hash(name,12)]->votes = 1;
array1[Hash(name,12)]->next = NULL;
for(int i = 0; i < 12 ; i++)
cout << endl;
cout << 3 << ": ";
if(array1[i]->votes != NULL)
cout << array1->firstName << " Votes: " << array1->votes;
cout << endl;
I guess i'm a little confused with the array of pointers, and what the values of the array positions are before any entries. If i insert an entry, is the array pointing to that entry, or is it actually the entry.
Any help would be appreciated.
PS: This is suppose to be a hash table using chaining. Also, i can individually print the entries that i know were hashed, so they seem to be being created and hashed successfully.