As far as I'm aware, there is no more allocation code. I don't even know enough to know what that really means. To show more code, here is how I use the first structure element that works:
Code:
int preyh(char command, struct creatures *prey)
{
move(command, prey);
grid[prey->position[0]][prey->position[1]]=1;
return 0;
}
Where it just sends the position array into the "move" function and changes it based on what command I gave (here I'm just moving a character around a 2D array of chars, and displaying - a 1 running around the screen, for example).
My main function is this:
Code:
int main(void)
{
char command;
struct creatures prey1;
struct creatures pred;
prey1.position[0]= 6;
prey1.position[1]= 6;
// pred.position[0]=8;
// pred.position[1]=14;
zerobox();
printf("Please enter a command ('q' to quit).\n");
do{
command=input();
preyh(command, &prey1);
//predator(&pred, &prey1);
printbox();
zerobox();
}
while(command != 'q');
gameover();
return 0;
}
I don't do anything with the structure anywhere else, so this should cover it. I just want to be able to feed the "pred" element into the move function as well, so that it can chase the "prey" around. I just don't understand why declaring it is crashing my program.
Since I know nothing about memory allocation, maybe the problem is that I haven't been doing it? Can you suggest any resources online for learning more? (I am not taking a class nor do I have a book, I'm just learning because it is a useful skill to help me with my research, so I'm limited to free learning).