Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6950269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:04:19+00:00 2026-05-27T14:04:19+00:00

I get this error over and over again when I run my project. Don’t

  • 0

I get this error over and over again when I run my project. Don’t know where is the problem. I know it’s about some free memory I used again, or a null pointer or access to a non exist memory but actually I checked all the pointers and they are declared as what they should to be.

Here’s the code:

#include <iostream>
using namespace std ;

typedef struct ND {
  int ID;
  char* Name;
  char* Address;
  int Age;
  double GPA;
  ND * next;
} NODE;

class HF {
private :
  int count;
  int size ;
  int prime;
  int a ,b;
  NODE ** HT;
public: 
  HF ();
  HF ( int n , int p , int a, int b);
  ~ HF ();
  int findindex(int key);
  bool insert (int ID,char* Name,char* Address,int Age,double GPA);
  bool retrieve (int & ID,char* & Name,char* & Address,int & Age,double & GPA);
  bool remove(int key);
  double GetLoadFactor ();
};

HF :: HF ()
{
  size = 100;
  prime = 997;
  a = 23 ;
  b = 88;
  count =0;
  HT = new NODE* [size];
  for (int i=0; i< size ; i++)
      HT[i] = NULL;
  }

HF :: HF ( int n , int p , int a, int b)
{
  size = n;
  prime = p;
  a = a;
  b = b;
  count = 0;
  HT = new NODE* [size];
  for (int i=0; i< size ; i++)
      HT[i] = NULL;
}

HF :: ~ HF ()
{
  NODE *p;
  for (int i=0 ; i<size ; i++)
  {
      while (HT[i] != NULL)
      {
          p = HT[i];
          HT[i] = HT[i] -> next ;
              delete p;
      }
  }
  delete  [] HT ;
}

int HF :: findindex(int key)
{
  int index ;
  index = (((a*(key)+b) % prime) % size) ;
  index = index % size ;
  return index;
}

bool HF :: insert (int ID,char* Name,char* Address,int Age,double GPA)
{
  int i ;
  NODE * n;
  n = new NODE;
  n -> ID = ID;
  n -> Address = Address;
  n -> Name = Name;
  n -> Age = Age;
  n -> GPA = GPA;
  n -> next = NULL;
  i = findindex(ID);
  if ( HT[i] == NULL)
  {
      HT[i] = n;
  }
  else
  {
      n -> next = HT[i];
      HT[i] = n;
  }
  count ++ ;
  return true;
}

  bool HF ::retrieve (int & key,char* & Name,char * &Address,int & Age,double & GPA)
  {
  int i ;
  NODE *p;
  i = findindex(key);
  if ( HT[i] == NULL)
  {
      return false;
  }
  else
  {
      p = HT[i];
      if ( HT[i] -> ID == key)// here is the break point
      { 
          key = p-> ID ;
          Name = p-> Name ;
          Address = p-> Address ;
          Age = p-> Age;
          GPA = p-> GPA ;
          return true ; 
       }
       while ( p != NULL)
       {
          if ( p-> ID == key)
          { 
              key = p-> ID ;
              Name = p-> Name ;
              Address = p-> Address ;
              Age = p-> Age;
              GPA = p-> GPA ;
              return true ; 
          }
          else
              p = p-> next ;
          }
    }
    return false;
  }
bool HF :: remove (int key)
 {

int i ;
NODE *p1 , *p2;
i = findindex(key);
if ( HT[i] == NULL)
{
    return false;
}

else
{
    p1 =p2 = HT[i];
    if(HT[i] -> ID == key)
    {
        HT[i] = HT[i] -> next;
        delete p2;
        return true;
    }


    while ( p2 != NULL)
    {
        if ( p2 -> ID == key)
        { 
            p1 -> next = p2 -> next ;
            delete p2;

            count --;
            return true;
        }
        else 
        {

            p1 =p2;
            p2 = p2 -> next;

        }
    }


}
return false;

 }

 double HF :: GetLoadFactor()
 {
double L;

L = (double) count/size ;
return L;
}

int main ()
{
double L;
int x,age;
char * name , *address;
double GPA;
HF UHashFunc1;
HF UHashFunc2( 11 , 7 , 3 , 0);

 UHashFunc1.insert( 6 , "Ahmed" , "Jenin" , 20 , 3.5);
 UHashFunc1.insert( 1 , "Sarah" , "Jenin" , 18 , 3.2);
 UHashFunc1.insert(40 , "Mohammad" , "Tolkrem", 19 , 3.0);
 UHashFunc1.insert(2 , "Ala'a" , "Jerusalem", 19 , 2.6);
 UHashFunc1.insert(41 , "Raghad" , "Tolkrem", 19 , 1.6);
 UHashFunc1.insert(80 , "Mohammad" , "Jenin", 22 , 2.7);
 UHashFunc1.insert(83 , "Murad" , "Nablus", 18 , 3.7);
 UHashFunc1.insert(44 , "Reem" , "Hebron", 19 , 2.9);
 UHashFunc1.insert(50 , "Wajde" , "Qalqelya", 20, 1.7);
 UHashFunc1.insert(42 , "Belal" , "Hebron", 20 , 3.4);
 UHashFunc1.insert(3 , "Ahmed" , "Nablus", 21 , 1.9);
 UHashFunc1.insert(84 , "Haitham" , "Nablus", 21 , 3.1);


cout <<"enter the ID you want to retrieve"<<endl;
cin>>x;
if(UHashFunc1.retrieve(x,name,address,age,GPA))
{
cout << "ID:"<<x<<endl;
cout << "Name:"<<name<<endl;
cout << "Address:"<<address<<endl;
cout << "Age:"<<age<<endl;
cout << "GPA:"<<GPA<<endl;
}
else
    cout<<"NOT FOUND"<<endl;

cout <<"enter the ID you want to retrieve"<<endl;
cin>>x;
if(UHashFunc1.retrieve(x,name,address,age,GPA))
{
cout << "ID:"<<x<<endl;
cout << "Name:"<<name<<endl;
cout << "Address:"<<address<<endl;
cout << "Age:"<<age<<endl;
cout << "GPA:"<<GPA<<endl;
}
else
    cout<<"NOT FOUND"<<endl;
L=UHashFunc1.GetLoadFactor();
cout << "The current load factor is : " << L <<endl;
UHashFunc1.remove(42);
L=UHashFunc1.GetLoadFactor();
cout << "The current load factor is : " << L <<endl;
x=84;
UHashFunc1.retrieve(x,name,address,age,GPA);
cout << "ID:"<<x<<endl;
cout << "Name:"<<name<<endl;
cout << "Address:"<<address<<endl;
cout << "Age:"<<age<<endl;
cout << "GPA:"<<GPA<<endl;
x=1;
UHashFunc1.retrieve(x,name,address,age,GPA);
cout << "ID:"<<x<<endl;
cout << "Name:"<<name<<endl;
cout << "Address:"<<address<<endl;
cout << "Age:"<<age<<endl;
cout << "GPA:"<<GPA<<endl;
x=50;
UHashFunc1.retrieve(x,name,address,age,GPA);
cout << "ID:"<<x<<endl;
cout << "Name:"<<name<<endl;
cout << "Address:"<<address<<endl;
cout << "Age:"<<age<<endl;
cout << "GPA:"<<GPA<<endl;

cout << "Enter The ID you want to remove"<<endl;
cin>>x;
if(UHashFunc1.remove(x))
    {
    L=UHashFunc1.GetLoadFactor();
     cout << "The current load factor after removing a record is : " << L <<endl;
}
else 
{ cout << "NOT Exist"<<endl;}

if(UHashFunc1.remove(2))
    {
    L=UHashFunc1.GetLoadFactor();
     cout << "The current load factor after removing a record is : " << L <<endl;
}
else 
{ cout << "NOT Exist"<<endl;}
 UHashFunc1.insert( 45 , "Amjad" , "Nablus" , 19 , 2.0);
 L=UHashFunc1.GetLoadFactor();
 cout << "The current load factor after adding a record is : " << L <<endl;
 if(UHashFunc1.remove(80))
    {
    L=UHashFunc1.GetLoadFactor();
     cout << "The current load factor after removing the record is : " << L <<endl;
}
else 
{ cout << "NOT Exist"<<endl;}
 if(UHashFunc1.remove(50))
    {
    L=UHashFunc1.GetLoadFactor();
     cout << "The current load factor after removing the record is : " << L <<endl;
}
else 
{ cout << "NOT Exist"<<endl;}

  UHashFunc2.insert( 5 , "Ahmed" , "Jenin" , 20 , 3.5);
 UHashFunc2.insert( 1 , "Sarah" , "Jenin" , 18 , 3.2);
 UHashFunc2.insert(9 , "Mohammad" , "Tolkrem", 19 , 3.0);
 UHashFunc2.insert(2 , "Ala'a" , "Jerusalem", 19 , 2.6);
 UHashFunc2.insert(8 , "Raghad" , "Tolkrem", 19 , 1.6);
 UHashFunc2.insert(100 , "Mohammad" , "Jenin", 22 , 2.7);
 UHashFunc2.insert(50 , "Murad" , "Nablus", 18 , 3.7);
 UHashFunc2.insert(23 , "Reem" , "Hebron", 19 , 2.9);
 UHashFunc2.insert(40 , "Wajde" , "Qalqelya", 20, 1.7);
 UHashFunc2.insert(17 , "Belal" , "Hebron", 20 , 3.4);
 UHashFunc2.insert(3 , "Ahmed" , "Nablus", 21 , 1.9);
 UHashFunc2.insert(7 , "Haitham" , "Nablus", 21 , 3.1);

 cout <<"enter the ID you want to retrieve from the 2nd Func"<<endl;
cin>>x;
if(UHashFunc2.retrieve(x,name,address,age,GPA))
{
cout << "ID:"<<x<<endl;
cout << "Name:"<<name<<endl;
cout << "Address:"<<address<<endl;
cout << "Age:"<<age<<endl;
cout << "GPA:"<<GPA<<endl;
}
else
    cout<<"NOT FOUND"<<endl;

cout <<"enter the ID you want to retrieve from the 2nd Func"<<endl;
cin>>x;
if(UHashFunc2.retrieve(x,name,address,age,GPA))
{
cout << "ID:"<<x<<endl;
cout << "Name:"<<name<<endl;
cout << "Address:"<<address<<endl;
cout << "Age:"<<age<<endl;
cout << "GPA:"<<GPA<<endl;
}
else
    cout<<"NOT FOUND"<<endl;

L=UHashFunc2.GetLoadFactor();
cout << "The current load factor is : " << L <<endl;
UHashFunc2.remove(2);
L=UHashFunc2.GetLoadFactor();
cout << "The current load factor is : " << L <<endl;
x=5;
UHashFunc2.retrieve(x,name,address,age,GPA);
cout << "ID:"<<x<<endl;
cout << "Name:"<<name<<endl;
cout << "Address:"<<address<<endl;
cout << "Age:"<<age<<endl;
cout << "GPA:"<<GPA<<endl;
x=1;
UHashFunc2.retrieve(x,name,address,age,GPA);
cout << "ID:"<<x<<endl;
cout << "Name:"<<name<<endl;
cout << "Address:"<<address<<endl;
cout << "Age:"<<age<<endl;
cout << "GPA:"<<GPA<<endl;
x=50;
UHashFunc2.retrieve(x,name,address,age,GPA);
cout << "ID:"<<x<<endl;
cout << "Name:"<<name<<endl;
cout << "Address:"<<address<<endl;
cout << "Age:"<<age<<endl;
cout << "GPA:"<<GPA<<endl;

cout << "Enter The ID you want to remove from the 2nd Func"<<endl;
cin>>x;
if(UHashFunc2.remove(x))
    {
    L=UHashFunc2.GetLoadFactor();
     cout << "The current load factor after removing a record is : " << L <<endl;
}
else 
{ cout << "NOT Exist"<<endl;}

if(UHashFunc2.remove(2))
    {
    L=UHashFunc2.GetLoadFactor();
     cout << "The current load factor after removing a record is : " << L <<endl;
}
else 
{ cout << "NOT Exist"<<endl;}
 UHashFunc2.insert( 45 , "Amjad" , "Nablus" , 19 , 2.0);
 L=UHashFunc2.GetLoadFactor();
 cout << "The current load factor after adding a record is : " << L <<endl;
 if(UHashFunc2.remove(100))
    {
    L=UHashFunc2.GetLoadFactor();
     cout << "The current load factor after removing the record is : " << L <<endl;
}
else 
{ cout << "NOT Exist"<<endl;}
 if(UHashFunc2.remove(9))
    {
    L=UHashFunc2.GetLoadFactor();
     cout << "The current load factor after removing the record is : " << L <<endl;
}
else 
{ cout << "NOT Exist"<<endl;}


cin>>x;



return 0;
 }

There are no building errors just these ones when break point

First-chance exception at 0x009437bd in Hash functions.exe:
0xC0000005: Access violation reading location 0x00000001. Unhandled
exception at 0x009437bd in Hash functions.exe: 0xC0000005: Access
violation reading location 0x00000001. First-chance exception at
0x009437bd in Hash functions.exe: 0xC0000005: Access violation reading
location 0x00000001. The thread ‘Win32 Thread’ (0x1e40) has exited
with code -1073741510 (0xc000013a). The program ‘[788] Hash
functions.exe: Native’ has exited with code -1073741510 (0xc000013a).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:04:20+00:00Added an answer on May 27, 2026 at 2:04 pm

    I was able to easily reproduce the error you ran into.
    You have a constructor for HF that takes parameters like this:

    HF :: HF ( int n , int p , int a, int b)
    {
        size = n;
        prime = p;
        a = a;
        b = b;
    

    As you can see the parameter names a and b are exactly the same as the member variable names. Hence HF::a and HF::b are never assigned values. Hence they are always uninitialized and contain garbage. Hence you get nothing but random values, and all the hashing stuff you are trying to do doesn’t work as a result.

    You should change the parameter names to something different. Say with capital letters perhaps:

    HF :: HF ( int n , int p , int A, int B)
    {
        size = n;
        prime = p;
        a = A;
        b = B;
    

    Once I do that, it solves all the memory corruption errors, and it runs to completion just fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get this error: Can't locate Foo.pm in @INC Is there an easier way
I get this error on an update panel within a popupControlExtender which is within
I get this error when I do an svn update : Working copy XXXXXXXX
I get this error:- You have an error in your SQL syntax; check the
We get this error in Visual Studio 2005 and TFS very often. Can anyone
i get this error {Method 'System.DateTime ConvertTimeFromUtc(System.DateTime, System.TimeZoneInfo)' has no supported translation to SQL.}
I get this error message when installing SQL 2005 Analysis services. The cabinet File
I get this error: System.Reflection.TargetException: Object does not match target type. when trying to
I get this error when debugging my ASP.NET web application after I trigger an
I get this 'error' when running PEVerify on a custom generated assembly. [MD](0x8013124C): Error:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.