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 7615545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:40:08+00:00 2026-05-31T02:40:08+00:00

Ok, I am beyond exhausted with this problem, so I figured I would get

  • 0

Ok, I am beyond exhausted with this problem, so I figured I would get some outside help. The program holds a “database” of Personnel which include Employees and Students. Each student has a binary tree of “books” that the user can insert and search through. I need to take in a name of a student, find the Personnel node that corresponds to that particular student, and add a book to that student’s bookTree.

The error message I’m getting is
“Unhandled exception at 0x013c53a0 in Homework4.exe: 0xC0000005: Access violation reading location 0xcccccd1c.”, which I assume means I’m messing up a pointer somewhere. The callstack shows line 512 (and therefore the book_traverse() ) as the problem maker.
This is what I have so far (omitting the unnecessary code): Thanks in advance!

class PersonnelNode {       // This is a container class
private:
    Personnel       *pNode; // It contains a Personnel class
    PersonnelNode   *pNext; // pointer used to form a linked list
public:
    void setNode(Personnel *pNode) { this->pNode = pNode; }
    void setNext(PersonnelNode *pNext) { this->pNext = pNext; }
    Personnel* getNode() { return pNode; }
    PersonnelNode* getNext() { return pNext; }

    PersonnelNode() {       // constructor
        pNode = NULL;
        pNext = NULL;
    }
} *head = NULL; // declare a global pointer variable head

….

struct Book {
  char title[75];
  char url[75];
  char key;
  Book *left;
  Book *right;  

  Book(char *title, char *url) { // Constructor
    strcpy_s(this->title, title);
    strcpy_s(this->url, url);
    key = title[0];
    left = NULL;
    right = NULL;
  }
};

….

class Student : public Personnel { //inherit from Personnel
   ... (omitted the unnecessary code)
   Book *bookTree;


   //BookTree = NULL in constructor
}

….

int insert_book() {
   PersonnelNode *temp, *prev;
   Personnel *person;
   Student *student;
   Book *newBook;
   char title[75], url[75], sName[75];
   temp = head;

   cout << endl << "@Inserting book node.........." << endl;
   cout << "Enter the student name: ";
   cin.ignore();
   cin.getline(sName, 75);
       //*****My error is probably below here?
   while (temp != NULL) {
       person = temp->getNode();
       if (sName != person->getName()) {
           prev = temp;
           temp = temp->getNext();
       }
       else {
           student = (Student *) person;
       }
   }
   cout << "Enter the book title: ";
   cin.getline(title, 75);
   cout << "Enter the URL: ";
   cin.getline(url, 75);
   newBook = new Book(title, url);
   book_traverse(student->bookTree, newBook); //LINE 512
   return 0;
}

….

//***Recursive function to insert book
void book_traverse(Book* root, Book* newBook) { //Is this right?
   if (root == NULL)                           //I tried Book* &root, but then
    root = newBook;                        //the compiler doesn't like root==NULL
   else if (newBook->key < root->key)
    book_traverse(root->left, newBook);
   else
    book_traverse(root->right, newBook);
}
  • 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-31T02:40:09+00:00Added an answer on May 31, 2026 at 2:40 am

    I think you need Book**

    void book_traverse(Book** root, Book* newBook) 
    

    and then use *root instead of root everywhere, e.g.

    *root = newBook
    

    Otherwise in book_traverse you are changing the local copy of root.

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

Sidebar

Related Questions

This is beyond my level and I need some help. In the htaccess make
Is there some optimal value for ConcurrencyLevel beyond which ConcurrentHashMap's performance starts degrading? If
For reasons beyond the scope of this post, I would like to verify in
For reasons beyond the scope of this post, I would like to verify in
Due to constraints beyond the scope of this post, I need to modify some
I would like to use Beyond Compare inside Eclipse. The problem at hand is,
For some reason beyond me I can't access the mysql server on a machine.
When you move beyond using one instance for your database, what is the best
I read and article talking about moving beyond 960px width for websites. This width
Beyond work, some friends and I are trying to build a game of sorts;

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.