Mail Archives: djgpp/1996/12/15/08:20:15
On Sat, 14 Dec 1996, Bill Lachance wrote:
> Ahoy there,
>
> I'm re-writing my tile-based game under Allegro to work better,
> cleaner, and faster. That means switching from global variables
> to pointers. ;)
>
> For some reason though, when I try to assign values to my pointer
> to player structures, the thing crashes.
>
> I've initialised them like so: player *plyr[3] (the game will
Do you really need to declare it as "player *plyr[3]"? If so, you need to
allocate memory for the pointers to pointer and for the pointers
themselves. Example:
player **plyr;
int x;
plyr = (player **)malloc(3 * sizeof(player *));
for (x = 0; x < 3; x++)
plyr[x] = (player *)malloc(sizeof(player));
/* of course, you need to test to see if == NULL, but this is just
an example */
If you can simply declare it as
player plyr[3];
then access it with "plyr[0].X = 4960"
> support up to three players, and the array seemed
to be the > best way of supporting that). But when I try a stunt like:
> plyr[0]->X=4960, the program crashes abruptly (I've isolated the
> problem).
>
> Am I breaking some unknown rule here?
>
> Bill Lachance
> billl AT synapse DOT net
>
---Michael Phelps
morphine AT cs DOT jhu DOT edu
CH3
|
N
/ |
______/ |
/ \ CH2
_____/ \__|__
// \\ / | \\
// \\______/___CH2 \\
\ / \ /
\______/ \_____/
/ ------ \ / \
OH \ / OH
O
Morphine
- Raw text -