Hello, i'm doing my home work, it's about managing a library, i created 4 trees as required in my assignment.

The problem arises with RemoveCategory function. I just don't know why but each time i try to remove books in order like this (the names of the books are in "File.txt")

_ Remove Tobie Lolness
_ Remove 1 ve
_ Remove No family
--> Problem arises here, saying that there is a heap corruption. I tried debugging, and when the program get to the line delete [] p->pCategory , it says "heap corruption".

I'm new to this, i don't understand what it's trying to say and how to solve this crazy problem, because when the order is different, the program still runs smoothly ~X(

Help me please ^:)^ My code is attatched below

That code is too big for anyone to bother looking at. Try eliminating code to produce a small but complete code sample that exhibits your problem. If you get lucky, you will find/fix the problem in the process of producing that small code sample. If not, people will be more willing and able to help.

Odds are, the cause is an invalid operation on a pointer in code executed before the line where the "heap corruption" is reported. Invalid operations with a pointer include dereferencing a pointer that doesn't actually point at anything valid (eg a NULL, or an uninitialised pointer) or falling off the end of an array (eg accessing element 10 in a 5-element array).

Thanks for you reply, i have tried my best to delete other functions, i just kept the add and remove function.

Please just look at the remove functions, especially the RemoveCategory function, all of the problems just arise there. Can you just remove the books in the order i mention and do you meet the same error like i do :-/, plz :|

I consider checking if i delete any NULL pointer, but still, i'm not deleting any NULL things, i just don't know why the dynamic array is right there and i can't delete it ~X(

Oh, silly me, i have found my problems, the heap corruption occurs because i have not allocated new memory but use the same memory. Thanks very much for your regards :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.