when the last member (down) is acsessed, it crashes.
Is there somthing wrong with how i declared this? All the other members work fine.Code:struct key{bool left; bool right; bool up; bool down;};
DW
when the last member (down) is acsessed, it crashes.
Is there somthing wrong with how i declared this? All the other members work fine.Code:struct key{bool left; bool right; bool up; bool down;};
DW
If something is going wrong during runtime, then no, everything is okay with that declaration. It is something wrong with how you are using it in your code. Post your code.
If you are getting an error when you compile, post the error.
It may be crashing because it was never initialized. Some compilers will do that, where others will just tell what happens to be in that memory block at that time.
no, if the program's crashing, it has little to nothing to do with the comper...Originally Posted by skorman00
I think what you mean is that some compilers will give you an error and halt compilation, where others will just compile the program with maybe a warning, and the program will give you the contents of that memory address...
edit: this thread should never have been started: http://cboard.cprogramming.com/showthread.php?t=53495
Last edited by major_small; 06-01-2004 at 03:54 PM. Reason: not a memory address
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
>> edit: this thread should never have been started: http://cboard.cprogramming.com/showthread.php?t=53495
yup yup i know. i acidently clicked new thread, instead of post reply
silly me. Sorry about that!
Regardless, thats where the code is, and can anyone see anything wrong with it? it crashes during
cheers, and sry again about the double post ;DCode:void User_Laser::Collision(Enemy *Baddy[4][8], User_Laser *laser) { int i,k; for(i=1;i<5;i++) { for(k=1;k<9;k++) { if(laser->y1 <= Baddy[i][k]->Baddy_Collision.left) { if(laser->Bullet.top >= Baddy[i][k]->Baddy_Collision.top && laser->Bullet.top <= Baddy[i][k]->Baddy_Collision.right && Baddy[i][k]->Dead == false) { Baddy[i][k]->Dead = true; laser->Obsolete = true; } } } } }
DW
I don't see where any key object is created or accessed...
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Check your for loops. You're overstepping your array bounds.
should beCode:for(i=1;i<5;i++)
andCode:for(i=0;i<4;i++)
should beCode:for(i=1;i<9;i++)
Remember that arrays are indexed starting with 0 -- so an array with 4 elements would have indices 0-3. (not 1-4)Code:for(i=0;i<8;i++)
-tf
Looks like that's your answer deathwraith. Keep it in the same thread next time though.
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
>>Keep it in the same thread next time though.
Will do! Again, my bad.
I changed the bounds of all my arrays( <5 to <4, <9 to <8, etc), and low and behold, it work! (imagine that!)
But when i changed the bounds down by one, only a 3 by 7 array of baddies appeared, as opposed to a 4 x 8. how do i fix this?
This is my current newing...
this is what I tried, but didn't solve the problem...Code:for(int k=1;k<5;k++) { for(int z = 1;z<9;z++) { Baddy[k][z] = new Enemy(z,k); } }
Code:for(int k=1;k<6;k++) { for(int z = 1;z<10;z++) { Baddy[k][z] = new Enemy(z,k); } }
how do i change this so i get my desired 4 x 8 array again? thanks for the help!
cheers
DW
'k' and 'z' should start at zero thinks I:
I thought that's what you had changed.Code:for(int k=0;k<5;k++) { for(int z = 0;z<9;z++) { Baddy[k][z] = new Enemy(z,k); } }
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
When I do that, should i keep the other counters from <5 && < 9 and starting at 1 or 0?
DW
depends on how they are used. If the counters are used to keep track of how many times the body of the loop is done, then both ranges are equivalent and no biggy either way. However, if the counter is used as an array index, then you can get into trouble if the counter is out of range for the array.
Example of looping through an array:
Note that i starts at 0, and the loop condition is "i < (size of the array)". Also note that this loop condition only lets the loop keep going until i reaches 19; 20 never gets run. So altogether 20 elements are checked, starting at 0 and ending at 19.Code:MyStruct array[20]; //There are 20 elements in the array for(int i = 0; i < 20; ++i) //The loop looks like this. { //do something with array[i]. }
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
A general rule to keep in mind is that all true number systems start from zero. You will save yourself many headaches by following this rule.
Yup, well that worked well. I'm just learning c++ coming from VB, so I forget every once and a while (read normaly ) that they start at 0! Cheers, and thx for the help!