Hi Raymond,
You provide only a small snapshop of your code. It is difficult
to come with a diagnostic. Also, please, when sending mails to roottalk
indicate which version of Root and the machine.
I could run the following script on my machine without problems.
Using Root 2.25/02
{
double **array;
const int xsize=4;
const int ysize = 12;
array= new double *[ysize];
int i,j;
for (j=0;j<ysize;j++){
array[j]=new double [xsize];
for (i=0;i<xsize;i++) array[j][i] = 10*j+i;
}
for (j=0;j<ysize;j++) {
double *x = array[j];
for (i=0;i<xsize;i++) {
printf(" x[%d][%d]=%g",j,i,array[j][i]);
}
printf("\n");
}
}
Rene Brun
On Wed, 6 Sep 2000, Raymond Fliller III wrote:
> - Rooters
>
> I'm quite new to ROOT, so much so that my unbilical cord is still attached.
>
> I'm trying to make a 2 dimensional dynamically allocated array to read in an
>
> ASCII file. The way I have done it in other programs is:
>
> double **array;
>
> ..... later on
>
> array= new double *[xsize]
>
> for (i=0;i<xsize;i++){
>
> *(array+i)=new double [ysize]
>
> }
>
> Then when I go to set array[i][j], I get a segmentation fault, for
>
> any i,j value.
>
> I'm assuming that this is the correct way as it has worked for me in C++
>
> in the past, unless I'm doing something incredibly wrong and have just
>
> gotten lucky in the past. Thank's a lot.
>
> ==============================================================================
> Ray Fliller: rfliller@bnl.gov Office Phone: (631)-344-6124
> C-A Accelerator Physics
> Building 911
> Brookhaven National Lab
> Upton, NY 11973 Office: Room 211
> ==============================================================================
>
>
>
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:32 MET