Thread: Multidimensional array: read errors?

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    1

    Multidimensional array: read errors?

    Am using Metrowerks CodeWarrior, and I am working with a two-dimensional dynamic array.

    Sometimes the nested loop
    for(i=0;i<r;i++)
    {
    for(j=0;j<s;j++)
    {
    do_something_to(array[i][j]);
    }
    }

    doesn't quite behave as it should. After significant debugging, I have found that it doesn't always retrieve the array value it's supposed to. For example, when i=4, j=0, it retrieves array[0][0] instead of array[4][0].

    Does anyone know how this might be fixed?

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    That sounds suspicious...Does it only happen with dynamic arrays? Maybe you could post a short example program that we can compile.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Post the declaration of do_something_to(...).

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 05-29-2009, 05:48 AM
  2. Multidimensional Array in a Structure
    By Night_Blade in forum C Programming
    Replies: 3
    Last Post: 04-04-2005, 08:14 PM
  3. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  4. Replies: 1
    Last Post: 03-30-2004, 02:57 PM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM