Weird bug I cannot catch..

http://pastebin.com/esxAR3wY
This is my source code here...It is simply too big and ugly to fit in here, so I used this site..
If anyone can paste the code into his compiler and help me I will be grateful.
Everything works except for the "addEntry" function (and I am guessing "resizeArrayCopy" function too)..so if you are willing to help me, look there.
My problem basically is:
When I set the buffer size to 4, then load a file that has 4 entries, then I try to add a new entry from the menu, entry number FIVE just shows up blank after that. Entries after this entry are perfectly fine tho.
When I load a file that has less than 4 elements, then fill up the buffer with my data, the FIFTH element shows some strange characters, and (I think, not 100% sure) that in this case, entries six and onward work perfectly. I have been trying to catch the problem this entire day, and couldn't. If you are willing to help me, you definately need to compile the code and run the program in order to see for yourselves what exactly is wrong, since the code is very ugly written and it is (quite) big..
closed account (o3hC5Di1)
Hi there,

People are generally reluctant to just copy and compile code which they don't know they can trust, for obvious reasons.

If you suspect the addEntry function to cause trouble then please copy that into the thread and we'll go from there :)

All the best,
NwN
If you are willing to help me, you definately need to compile the code and run the program in order to see for yourselves what exactly is wrong, since the code is very ugly written and it is (quite) big..


I am willing to help you... but not by debugging your very ugly written code (by your own admission) for you.

I suggest you try to redesign your entire program: with the goal of keeping everything as simple as possible.

For starters, don't use C arrays and dynamic memory allocation anymore. Instead, use Containers to store your data: memory management will be automatic and therefore adding, removing and copying things will be simplified.

http://www.cplusplus.com/reference/stl/
closed account (zb0S216C)
Catfish2 wrote:
"don't use C arrays and dynamic memory allocation anymore."
Zarkon, ignore this. Dynamic memory allocation is an invaluable feature.

Catfish2 wrote:
"Instead, use Containers to store your data: memory management will be automatic and therefore adding, removing and copying things will be simplified."

The STL containers are optimised for general use and therefore, are not suitable for everything.

Zarkon, what I recommend to you is this: Document your program. This involves planning your program with flow charts, and written descriptions on how you would tackle various scenarios. When you feel comfortable with your program, begin creating it. When you encounter bugs, use your debugger. Know that a well-planned program is key and is likely to reduce the amount of bugs in the final product. Building a program a program without a plan is like building a house without the blueprints: Things are missing, parts don't fit, and collapses in the end.

Wazzak
Last edited on
Zarkon, ignore this. Dynamic memory allocation is an invaluable feature.

I wouldn't have issue with that quotation, if only you gave a better justification than just saying they're "an invaluable feature". In OP's case, they're potentially a source for bugs; so unless he's required to do things this way, I stick to what I said: he should simplify the code.

The STL containers are optimised for general use and therefore, are not suitable for everything.

Wouldn't you say the same thing if they were, hypothetically, for "specific use"?
Anyway, they'd be suitable for keeping Entry objects.

Edit: missing letters.
Last edited on
Topic archived. No new replies allowed.