Thread: Problem accessing 3d array in loop...

  1. #1
    Cereal Killer
    Join Date
    Jun 2004
    Posts
    8

    Problem accessing 3d array in loop...

    Hi, I have a really weird problem I can't explain.

    I have created a 3d array which is 10x10x5. Right after the function I use to create it, I can loop through all the components fine and it sends the data out, however, when I send the array to a different function to use in there, I can either a) access all the parts by specifying them manually e.g. array[0][0][0] or using a var on ONE component i.e. array[i][0][0] but if i try to do array[i][j][0] it crashes on me (assuming i'm looping through i, then j).

    Has anyone heard of a problem like this before. Maybe I haven't explained too clearly. Let me know and I'll try agaiN!

    Matt

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    what does your code look like when you pass the value and try to modify it?

  3. #3
    Cereal Killer
    Join Date
    Jun 2004
    Posts
    8
    Thanks for your response. It was my fault - turns out I wasn't allocating memory properly for a smaller array earlier in the function. Was pretty tough to find...

    i was using e.g:

    var=DEFINED*DEFINED;
    int array[var];

    whereas I should have been using

    int array[DEFINED*DEFINED]; or better..

    #define VAR DEFINED*DEFINED
    int array[VAR];

    ...schoolboy error...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Addition problem in loop
    By murjax in forum C Programming
    Replies: 3
    Last Post: 07-01-2009, 06:29 PM
  2. For loop through a 2D array - just for select rows
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 04-17-2009, 08:34 AM
  3. Problem with Dynamically Increasing Array of Integers
    By laserlight in forum C++ Programming
    Replies: 30
    Last Post: 07-04-2008, 07:27 AM
  4. simple array of char array problem
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 09-10-2006, 12:04 PM
  5. Initializing a 3D array w/o a loop.
    By funkydude9 in forum C++ Programming
    Replies: 5
    Last Post: 03-04-2004, 11:20 PM