1D array values into a 2D array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • foolygoofy26
    New Member
    • Jan 2006
    • 7

    1D array values into a 2D array

    I have been breaking my head by taking array[16] and passing it's values to arrayTwo[4][4], I'm trying to use a for loop for this, but it's just driving me crazy...can any body help me.

    Thanks.
  • Niheel
    Recognized Expert Moderator Top Contributor
    • Jul 2005
    • 2432

    #2
    Paste your code here; so that we can check it out. Use the CODE tag so that your code displays properly.

    Thanks
    niheel @ bytes

    Comment

    • foolygoofy26
      New Member
      • Jan 2006
      • 7

      #3
      Got it.

      I got it...thanks for the help anyways...if you still want the code I did, let me know...when i get home I'll post it here.

      Comment

      • Niheel
        Recognized Expert Moderator Top Contributor
        • Jul 2005
        • 2432

        #4
        Sure, it would be greatly appreciated. It could help another developer.

        Thanks
        ~ KUB
        niheel @ bytes

        Comment

        • foolygoofy26
          New Member
          • Jan 2006
          • 7

          #5
          Ok, I did it a function. that takes 3 parameter. The first is an array called list and listSize is a constant with the value of the 16 elements. Since it's an array, the value is 15.

          matrix is the 4 by 4 array that we want to pass the values into.

          row is the number of rows.

          here is the function.


          void matricize(int list[listSize], int matrix[rows][columns], int rows)
          {
          //INPUT THE VALUES OF ONE-DIMENSION ARRAY INTO THE TWO-DIMENSION ARRAY
          int listSize=0;

          for (int counter1 = 0; counter1 < rows; counter1++)
          {
          for (int count=0;count < columns; count++)
          {
          matrix[counter1][count] = list[listSize];
          listSize++;
          }
          }
          }

          thanks for you help KUB

          Comment

          Working...