Link to home
Start Free TrialLog in
Avatar of Vasconcelos
Vasconcelos

asked on

retrieve matrix from a linear array

Hi, i want to retrieve a 2D array from a linear array data

How do i do it? :)
SOLUTION
Avatar of mrjoltcola
mrjoltcola
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Raheman M. Abdul
Raheman M. Abdul
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
How was the 2D array stored in the linear array data?
If you know the size of both arrays, and these arrays are fixed, you can do some neat shortcutting
(taking the necessary tests and saftey checks first, of course)
typedef struct 
{
   int row[10];
   int col[5];
}intArray;

int array[] = {1,2,3,4.5.6.7.8,9,10,11,..........};

// for a quick copy of the flat array into the 2D array
memcpy( &intArray, array, sizeof( array))

Open in new window

> Hi, i want to retrieve a 2D array from a linear array data
> How do i do it?
Before you dive into writing code for this, tell us, whether you can do this manually?
If so, can you take an example and show us how you will do it?
Looking at your example, we can suggest you how to write the code.
Avatar of Vasconcelos
Vasconcelos

ASKER

i already found a solution thanks to the first 2 answers, sorry for my delay :)
thanks :)