Archived

This topic is now archived and is closed to further replies.

Arrays of Structures

This topic is 6359 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Greets All! I have a structure called Basic_Sprite that contains a bunch of integers, and a DDraw surface structure. At the beginning of my code I do this: Basic_Sprite S_Sprite[1]; That works fine. Then I do this: LoadGraphic(&S_Sprite[0],"graphic1.bmp"); That fine(LoadGraphic is a function to...well...load a graphic ). Then I do this: LoadGraphic(&S_Sprite[1],"graphic2.bmp"); This causes the program to lock up tight. I have no clue why. Any suggestions? Thanks In Advance!

Share this post


Link to post
Share on other sites
Change it to:
Basic_Sprite S_Sprite[2];

This will allow you to use positions 0 and 1, whereas:
Basic_Sprite S_Sprite[1];
Allows you to use 0.

-Medgur

Share this post


Link to post
Share on other sites
C/C++ begins its indexing at 0. When you declare an array of size 1 (as in your example s_Sprite[1]), you only declare one element which is indexed as the zero element, so when you try to reference s_Sprite[1] you''re accessing invalid memory. declare the array as:

Basic_Sprite S_Sprite[2];

This will give you 2 elements and your code should work.


Share this post


Link to post
Share on other sites