Jump to content
  • Advertisement

Archived

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

DrewSmug

itializing arrays

This topic is 5132 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

i have an array of mine initialized like so... for(int c; c<20; c++) { for(int i; i<10; i++) { itsArrayB[c] = 0; } } i get an access violation when i do this. itsArrayB is a private array thing in my class and i am trying to initialize it in the constructor. is that bad? because it works right if i initialize it in any other function within my class. what gives, does anybody know why my vc++ compiler does this.

Share this post


Link to post
Share on other sites
Advertisement
First of all, are you sure that your array has enough elements? Secondly, what is the point of the inner loop? All it does is initialize the array to the same value 20 times.

edit: just noticed, the loop should read as this:



for(int c=0; c<20; c++)
{
for(int i=0; i<10; i++)
{
itsArrayB[c] = 0;
}
}


Note that the loop counters start at 0, otherwise they are assigned a random number and will go out of bounds of your array.

[edited by - eleusive on May 6, 2004 7:51:57 PM]

Share this post


Link to post
Share on other sites
first off sorry for the typo(it happens)
i meant

itsArrayB[c][i]


so that way there are enough elements

but Deyja was right, i just needed to initialize my lame counters. i would have guessed that my compiler would have cought something like that though. but yea, thanks for your help

[edit] the forum is what actually made my syntax look wrong so i stuck it in those source tag things.

[edited by - drewsmug on May 6, 2004 8:13:12 PM]

Share this post


Link to post
Share on other sites
naw i declared that right.
but i have a new array initialization question.
here is my new array


for(c; c<20; c++);
{
itsArrayY[c] = ((c * 20) + 4);
}


i thought this would initialize the array so that...
itsArrayY[0] = 4;
itsArrayY[1] = 24;
itsArrayY[2] = 44;
and so on continually incrementing itself by 20

but it doesn''t do that. does anybody know what''s wrong with my math.

Share this post


Link to post
Share on other sites
Again, what''s the initial value of c?


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan

Share this post


Link to post
Share on other sites
Tell us what it is doing, and please include ALL pertinent code in your source tags. This includes ALL declarations previously made, and all assignments previously made. Include the declarations of your arrays and other variables and their assignments and it is a lot easier to offer real help, and not ask questions that shouldn''t have to be asked.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!