Thread: An [n][n][m] array...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    26

    An [n][n][m] array...

    Sorry for post a lot

    My problem is like this: I have to define an n+n matrix. Obviusly that is not a problem. The question is that in each element of the matrix, I have to define, say, k elements more.

    It would be like this:


    Code:
    for(i=0;i<10;i++){
     for(j=0;j<10;j++){
      for(k=0;k<NSTEPS-1; k++){
      cx[i][j][k]=i*k; //This is not obviusly what I'm tring to do
      cy[i][j][k]=j*k;
      printf("&#37;f %f \n",cx[i][j][k],cy[i][j][k]);
      }
     }
    }
    But my compiler say I defined in a wrong way cx and cy. I tried to define them as

    Code:
    double cx[11][11][NSTEPS],cy[11][11][NSTEPS];
    &#191;Do anybody know how can i defined that arrays? Thanks!

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Works for me. May-be there's an error on the previous line? (Posting the actual error message and actual code that produces it might be helpful.)

    However, note that you are skipping the last element of each dimension in your loops.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Maybe one of these reasons:
    cx, cy are not declared at the start of a block.
    NSTEPS isn't a #define constant.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Aug 2007
    Posts
    26
    This is stupid. I put the last element I was forgotten, and I defined in a correct way i and j.

    The thing is that initially I tried to defined the matrix with decimal numbers, like

    for(i=0;i<4.0;i=i+0.04), but then a corrected it, and I forget to defined i and j like integers. I'm very embarrased with you. Sorry for that stupid mistake. I promise check my codes after asking.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM