Thread: Multi-Arrays

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    65

    Multi-Arrays

    When ploting the multi array can one use the RC-convention method Xsubscript (row,column) like on
    Code:
    arraytest[2][4]
    
    [1][2]
    [3][4]
    [5][6]
    [7][8]
    and I wanted to say the value of 5 would be at arraytest[3][1] or would I say arraytest 3,1. How could I tell presay a user 5 is at X (and no not the coding, I can do that). In theory I have talked to my Math teacher about matrix's and noticed that it was just a mulit-d-array.

  2. #2
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    this is how i would go.

    no 5 is located at row no 3 at col 1


    ssharish2005

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    65
    ok when making an array the first [x] represents amount in the row the second [x] represents columns. Like dan[4][2]
    Code:
    [1] [2] [3] [4] *i assume this is correct
    [5] [6] [7] [8]
     or 
    [1] [2]
    [3] [4]
    [5] [6]
    [7] [8]

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    dan[i] is array containing 2 elements
    Code:
    {{0,1},{2,3},{4,5},{6,7}}
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    65
    so vert dan[i][x] i is the value of how many group of rows are and [x] declares how many elements/spaces are in a single row
    Code:
      i
    x[][][]
      [][][]
      [][][]
      [][][]
    so this would be dan[i][3]?
    Array of Dan containing 3 elements, i will truly only decide how many in theory how many rows there will be.
    so i is the L and x is the W. L*W is size of array.
    Last edited by KoG Metalgod; 12-06-2006 at 07:29 AM.

  6. #6
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    I don't undestand what do you mean

    int array[4][7]

    declares array of 4 elemets
    each elemet (array[0], array[1], array[2] and array[3]) is also array containing 7 ints

    so array[2][5] is the 6th element of the 3rd array (indexes are zero based)
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  7. #7
    Registered User
    Join Date
    Nov 2006
    Posts
    176
    rows and columns would be somthing you have acheived with the placment of data in the arrays,
    and the way in which that data is accessed. As vart is saying, there really is no rows or columns
    if you were to look at this in memory it would just be 1 "column". You specify by the algorithms you use, what represents a row and what represents a column.

    for example
    Code:
    #include <stdio.h>
    
    int main(void)
    {
            int i, j;
            int ary[3][5] = { {1, 2, 3, 4, 5},
                              {1, 2, 3, 4, 5},
                              {1, 2, 3, 4, 5} };
    
            for (i = 0; i < 3; i++)
            {
                    for (j = 0; j < 5; j++)
                            printf("%d ", ary[i][j]);
                    printf("\n");
            }
    
            for (i = 0; i < 5; i++)
            {
                    for (j = 0; j < 3; j++)
                            printf("%d ", ary[j][i]);
                    printf("\n");
            }
    
    
            return 0;
    }
    output:
    1 2 3 4 5
    1 2 3 4 5
    1 2 3 4 5
    1 1 1
    2 2 2
    3 3 3
    4 4 4
    5 5 5

    so which for loop is representing data in the correct row/column's? That depends on what way other code in the program, uses and "sees" the data. It could be either, its up to you, it just has to be consistant

  8. #8
    Registered User
    Join Date
    Nov 2006
    Posts
    176
    Code:
    #include <stdio.h>
    
    int main(void)
    {
            int i, j;
            int ary[3][5] = { {1, 2, 3, 4, 5},
                              {1, 2, 3, 4, 5},
                              {1, 2, 3, 4, 5} };
    
            int *ptr = &ary[0][0];
    
            for (i = 0; i < 15; i++)
                    printf("%d\n", *ptr++);
    
            return 0;
    }
    output:
    1
    2
    3
    4
    5
    1
    2
    3
    4
    5
    1
    2
    3
    4
    5

    or maybe even though you've used a 2 dimensional array (which is not needed in this case), you just want it to have 1 "colunm" or "row".

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fscanf for multi dimensional arrays
    By rambos in forum C Programming
    Replies: 7
    Last Post: 05-06-2008, 03:26 AM
  2. Pointers and multi dimensional arrays
    By andrea72 in forum C++ Programming
    Replies: 5
    Last Post: 01-23-2007, 04:49 PM
  3. Replies: 6
    Last Post: 04-26-2004, 10:02 PM
  4. concatenating single chars to multi char arrays
    By TJJ in forum C Programming
    Replies: 7
    Last Post: 11-20-2003, 04:09 AM
  5. Pointers to multi dimensional arrays.
    By bartybasher in forum C++ Programming
    Replies: 2
    Last Post: 08-25-2003, 02:41 PM