Jump to content
  • Advertisement
Sign in to follow this  
Dogh Quch

Problems with Dynamic Matrix....

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

Hello people, I'm having a really hard time trying to use a dynamic matrix in my program. I never had to use something like this and when I tried it never worked...but this time is the only way! So, this is how I'm doing it, I have the declaration of the matrix like this: int **mi_Bord; And I’m making a malloc like this: MyIsoMap->mi_Bord=(int **) MALLOC(((MSize/2)+1)*sizeof(int *)); for (i=(MSize/2)+1; --i; ) MyIsoMap->mi_Bord=(int *)MALLOC(((MSize/2)+1)*sizeof (int)); They are in capital letters because this is Brew code and not C standard. The problem is, when I try to make an value attribution there is an error. I know the way for doing an attribution is like this: **iso->IsoTeste.mi_Bord[j]=1; But the compiler only let me do like this: iso->IsoTeste.mi_Bord[j]=1; And that is why it happens an error! Can some one help me about the correct way of doing this?

Share this post

Link to post
Share on other sites

first let me say that I don't know Brew, so I'll just have to tell you the things I know hold for C; hope they apply as well.

Your memory allocation seems to be in order (although right now, I am really not sure, if it isn't supposed to be sizeof(int) as well in the first call---try that for a change, but it's a wild guess), but what I do not get is the way you call your array.
Usually it's like this:

int **matrix;

matrix = (int **) malloc (columns * sizeof(int)); // maybe sizeof(int *) -- can't remember.

for (int i = 0; i < columns; i++) {
matrix = (int *) malloc(rows * sizeof(int));

and then you should be able to access it via:

matrix[x][y] = 19;

Maybe not much of a help... But you can give it a try, maybe it'll help...

BTW: Maybe you have the chance to switch to C++?! It's easier there...

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!