need help with

Write your question here.
I am using hash table to store a string. I used the bucket to store my string. However, when I compile it, it just got stop debugging at the strcmp() at the line 46 and also is there any wrong with the way I calculated the n_element. Any help is appreciated
thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  

using namespace std;

const int MAX_ARRAY_ELEMENT = 20;
class Registration
{
    public:
        Registration()
        {
            next = nullptr;
        };
        Registration(char * email_id, Registration * n_next)
        {
            long length = strlen(email_id);
            for (int i = 0; i < length; i++)
            {
                email += email_id[i];
            }
            next = n_next;
        };
    
        string email;
        Registration * next;
};

class saveInfomation
{
    private:
        int element;
        Registration * email [];
    public:
        saveInfomation();
        void addEmailToSystem(char * email_id);
};

#endif /* funproject_h */
#endif /* funproject_h */

 // this is function in .cpp file

#include "funproject.h"


saveInfomation::saveInfomation()
{
    for (int i = 0; i < MAX_ARRAY_ELEMENT; i++)
    {
        email[i] = new Registration();
        email[i]->email = " ";
        email[i]->next = nullptr;
    }
}

void saveInfomation::addEmailToSystem(char * email_id)
{
    long length = std::strlen(email_id);
    int size_string;
    int n_element;
    Registration * e = new Registration(email_id, nullptr);
    Registration * current;
    int max_array_element = MAX_ARRAY_ELEMENT;
    for (long i = 0; i < length; i++)
    {
        size_string += email_id[i];
    }
    n_element = max_array_element % size_string;
    
   
    current = email[n_element]->next;
    while(current != nullptr)
    {
        
        if (strcmp(current->email.c_str(), email_id) == 0)
            break;
        current = current->next;
    }
    current->next = e;
    // email[n_element]->next = e;
    
    //email[MAX_ARRAY_ELEMENT] = new  Registration();
}
Last edited on
Hi,

could you show us the class/struct/definition of mystring->email.c_str()
hi programmer007
thanks for your replying, i have updated the class mystring->email.c_str()
Last edited on
Topic archived. No new replies allowed.