1. make sure you are not accessing any arrays with an index that is out of
bounds.
2. using gdb, set a watch point on the variable to figure out exactly where
the value you are interested in is being changed from 5 to 134524505. Here
is a guick guide to doing that:
gdb hzip
(gdb) set args a.txt a.txt.hzip
(gdb) b main
(gdb) r
...
use "s" for "step into", "n" for next (step over) to find the place wher the
value is being set to 5.
(gdb) p X
[ above "X" is the variable containing the value 5, this would print
something like "X=5" ]
(gdb) p watch X
[ if X includes a local variable, you may need to one step further: for
instance, if X is "p->value", where p is a pointer to a structure inside
some subroutine (i.e., p is a local variable), and p->value somehow
mysteriously gets modified after leaving this subroutine, then do the
following ]
(gdb) p &X
(gdb) watch *(int *) <value printed by last command>
[ obviously you replace the part in angle brackets with a number, it is the
address of the thing that changes... for simplicity I assume that value is
an "int" ]
(gdb) r
Then gdb should stop when the value of X changes, no matter where in the
program this happened. This is a very good way to locate such memory bugs.
Post by Ho Ivan Kar KitWhen I input a .txt file with less than 5 different symbols, (eg.
abcde)... my program works.... but when i input more than 5 different
symbols (eg. aabbccdeFG)..... the key values in the nodes get replaced
my it's memory number. eg. a node containing a key of 5 gets replaced by
134524505.
Can someone advise me on what to do here?