470,863 Members | 1,139 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,863 developers. It's quick & easy.

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.
Jan 29 '06 #1
4 9591
Niheel
2,449 Expert Mod 2GB
Paste your code here; so that we can check it out. Use the CODE tag so that your code displays properly.

Thanks
Feb 3 '06 #2
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.
Feb 3 '06 #3
Niheel
2,449 Expert Mod 2GB
Sure, it would be greatly appreciated. It could help another developer.

Thanks
~ KUB
Feb 3 '06 #4
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
Feb 10 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by csx | last post: by
8 posts views Thread by Tweaxor | last post: by
9 posts views Thread by buda | last post: by
1 post views Thread by Stephen | last post: by
11 posts views Thread by rayreeves | last post: by
5 posts views Thread by Stephen3776 | last post: by
2 posts views Thread by yeshello54 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.