 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Azrin Aris Guest
|
Posted: Fri Feb 09, 2007 9:11 am Post subject: Loading data from multiple files to a 2D array |
|
|
Hi,
I'm using BCB6 and I trying to load 2D data (100x100) from 4 files into
a 200x200 array in memory. Here is the code
//Dynamically create a 200x200 data size;
short **Data;
Data = new short*[200];
for(int a=0;a<200;a++)
{
Data[a] = new short[200];
}
//Load data from files beginning top left quadrant
for(int r=0;r<2;r++)
{
for(int c=0;c<2;c++)
{
//load file according to quadrant e.g
//Data_00.dat is for array [0-99][0-99]
//Data_01.dat is for array [0-99][100-199]
//Data_10.dat is for array [100-199][0-99]
//Data_11.dat is for array [100-199][100-199]
String FileName = "Data_"+IntToStr(r)+IntToStr(c)+".dat";
TFileStream *FS =
new TFileStream(FileName,wmOpenRead|fmShareExclusive);
if(FS)
{
FS->Position = 0;
for(int l=0;l<100;l++)
{
//These variables is for calculating the offset pointer
int nr = l+(100*r);
int nc = 100*c;
FS->Read(&Data[nr][nc],sizeof(short)*100);
}
delete FS;
}
}
}
It seems I've loaded all data into the array without any problem. But
upon a closer inspection, the data for the 01,10,11 quadrant is not
accurate. Data for 01 which starts from array [0-99,100-199] is
accurate starting from [0,110] onwards. Data for 10 is accurate from
[110,0] onwards, data for 11 is accurate from [110,110] onwards.
It looks like the first quadrant 00 is taking extra space. I believe
this is a pointer issues but I cannot pin point where my mistake is. So
I'm asking for guidance from experts here to help me on this.
TIA,
Azrin |
|
| Back to top |
|
 |
Azrin Aris Guest
|
Posted: Fri Feb 09, 2007 9:11 am Post subject: Re: Loading data from multiple files to a 2D array |
|
|
Azrin Aris wrote:
| Quote: | Hi,
I'm using BCB6 and I trying to load 2D data (100x100) from 4 files into
a 200x200 array in memory. Here is the code
|
Sorry guys, I've posted to the wrong newsgroup. It should be to the
language.cpp group. Sorry again
Regards,
Azrin |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|