Arrays of Structures
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!
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
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
Because your array declaration only allocates space for one element. Use Basic_Sprite S_Sprite[2];
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.
Basic_Sprite S_Sprite[2];
This will give you 2 elements and your code should work.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement