arnaudtemme
02-13-2006, 07:19 AM
Guys,
I progressed well after your last comments. Now I am puzzled though. Watch this: (in main)
tillage_parameters till_pars;
declare_tillage_grids(&till_pars, ascii);
sprintf(ch," till_pars: field 10 10 = %d\n",till_pars.tillfields[10][10]);printf(ch);
read_integer(till_pars.fieldfile,till_pars.tillfie lds,ascii);
sprintf(ch," till_pars: field 10 10 = %d\n",till_pars.tillfields[10][10]);printf(ch); --> here the error occursIt gives the old "access violation" error message at runtime that normally would mean that int_grid 'till_pars.tillfields' has had no memory assigned in declare_tillage_grids(&till_pars,ascii). FYI, the typedefs for int_grid and tillage_parameters:
typedef int intmatelems;
typedef intmatelems *int_grid;
struct tillage_parameters
{
int_grid *tillfields;
char fieldfile[30];
};However, I have succesfully assigned memory to int_grid till_pars.tillfields and proved it with the first of the printf statements, which gives as output:till_pars: field 10 10 = 0The zero is the correct (uninitialized) value at this point. So something wrong must be happening in read_integer(till_pars.fieldfile,till_pars.tillfie lds,ascii);, where tillfields is correctly spelled in the code. This is that function:
void read_integer(char *filename, int_grid *intmatrix, geo_parameters ascii){
char f_name[30],str_1[80];
int row, col,
scan_cnt,
numtel,
scan_lon,
num_str;
double scan_do;
bool er_ifile=0;
FILE *p;
strcpy(f_name,filename);
strcat(f_name,".asc" );
p=fopen(f_name,"r" );
er_ifile=1; scan_cnt=0;
if (p==NULL){
(void)printf(" Error: unable to open file %s \n" , f_name);
er_ifile = NULL;
} else {
// code to read the header of the file
}
if( er_ifile != NULL ) {
for(row=0;row<ascii.nr;row++) {
for(col=0;col<ascii.nc;col++) {
scan_do = 0.0; scan_cnt++;
fscanf(p," %lf" ,&num_str);
intmatrix[row][col]= ( num_str );
}
}
}
fclose(p);
} Sorry, I can't completely get the tabs to work for me. My question: what is wrong with read_integer? A sister-function read_double with similar coding performs fine in the same test. Perhaps it is once more something to do with pointers, references and addresses?
I progressed well after your last comments. Now I am puzzled though. Watch this: (in main)
tillage_parameters till_pars;
declare_tillage_grids(&till_pars, ascii);
sprintf(ch," till_pars: field 10 10 = %d\n",till_pars.tillfields[10][10]);printf(ch);
read_integer(till_pars.fieldfile,till_pars.tillfie lds,ascii);
sprintf(ch," till_pars: field 10 10 = %d\n",till_pars.tillfields[10][10]);printf(ch); --> here the error occursIt gives the old "access violation" error message at runtime that normally would mean that int_grid 'till_pars.tillfields' has had no memory assigned in declare_tillage_grids(&till_pars,ascii). FYI, the typedefs for int_grid and tillage_parameters:
typedef int intmatelems;
typedef intmatelems *int_grid;
struct tillage_parameters
{
int_grid *tillfields;
char fieldfile[30];
};However, I have succesfully assigned memory to int_grid till_pars.tillfields and proved it with the first of the printf statements, which gives as output:till_pars: field 10 10 = 0The zero is the correct (uninitialized) value at this point. So something wrong must be happening in read_integer(till_pars.fieldfile,till_pars.tillfie lds,ascii);, where tillfields is correctly spelled in the code. This is that function:
void read_integer(char *filename, int_grid *intmatrix, geo_parameters ascii){
char f_name[30],str_1[80];
int row, col,
scan_cnt,
numtel,
scan_lon,
num_str;
double scan_do;
bool er_ifile=0;
FILE *p;
strcpy(f_name,filename);
strcat(f_name,".asc" );
p=fopen(f_name,"r" );
er_ifile=1; scan_cnt=0;
if (p==NULL){
(void)printf(" Error: unable to open file %s \n" , f_name);
er_ifile = NULL;
} else {
// code to read the header of the file
}
if( er_ifile != NULL ) {
for(row=0;row<ascii.nr;row++) {
for(col=0;col<ascii.nc;col++) {
scan_do = 0.0; scan_cnt++;
fscanf(p," %lf" ,&num_str);
intmatrix[row][col]= ( num_str );
}
}
}
fclose(p);
} Sorry, I can't completely get the tabs to work for me. My question: what is wrong with read_integer? A sister-function read_double with similar coding performs fine in the same test. Perhaps it is once more something to do with pointers, references and addresses?