Hello,
I wrote a piece of code (using dev c compiler on windows), in which one function, namely 'noise_block_reader' is called by another function (I am not an expert programmer). This function searches if input file contains 'NAME (or Name or name)' string, if it founds (input file may have this at multiple places), it stores the line no where this is found (part-1 of function and it works nicely, no error). After this, program goes one by one on the line numbers where it was founded and reads further data in that line. The data line has this format -> NAME: string double double double. So program looks if ':' appears after NAME and than it stores one string and three double data and these data are passed to the calling function (part-2 of function). The string is passed by double pointer. The first loop runs correctly, but after this error occurs (familiar error: .exe has encountered a problem....Please tell Microsoft.....). I think most probably I am doing some mistake in using double pointer, but I could not dig it out.I am using double pointer first time Here is the function (part-2 only with function declaration line) and also the part of calling function, where such function is called.
Function declaration line:
Code:
void noise_block_reader(FILE *fp_in, int start_line, int end_line, int nel,
char **var_name, double *el_data, int *err_index, FILE *fp_log)
Part-2 of function, where error occurs
Code:
/* PART-2: Reading the data (one string and three double) from the lines, in which NAME appears
format of line-> NAME: string double double double */
j=0;
counter=0;
if(k>0) /* Line with NAME: found*/
{
for(i=0; i<=(k-2)/2; i++)
{
printf("\n Skipped lines: %d\n",*(line_element+counter));
rewind(fp_in);
skip_line_file(fp_in, *(line_element+counter), fp_log, err_index);
fscanf(fp_in,"%c",&a);
brk_index=0;
/* checking the occurance of ':' after NAME (or Name or name)*/
while(1)
{
fscanf(fp_in,"%c",&a);
printf("\n %c",a);
getch();
if(a == ':')brk_index=1;
printf("\n BRKIND: %d",brk_index);
if(brk_index == 1)break;
if(a == '\n')break;
}
if(brk_index == 0)
{
*err_index=1;
return;
}
/* Reading the data after : */
printf("\n\n ------I= %d",i);
read_chk=fscanf(fp_in,"%s",*(var_name+i));
if((read_chk < 1) || (read_chk == EOF))
{
*err_index=1;
printf("\n\n ERR in read");
getch();
return;
}
printf("\n Passed");
//printf(fp_in,"\n\n %s",*(var_name+i));
read_chk=fscanf(fp_in,"%lf %lf %lf",el_data+j, el_data+j+1, el_data+j+2);
printf(" %lf %lf %lf",*(el_data+j), *(el_data+j+1), *(el_data+j+2));
if((read_chk < 3) || (read_chk == EOF))
{
*err_index=1;
return;
}
j=j+3;
counter=counter+2;
}
}
free(line_element);
printf("\n\n MEMORY FREE");
return;
Part of the calling function, where this function is called
Code:
char **pnoise_elem, *noise_elem[100];
int n_noise_elem;
double *noise_a_f_ph;
------//-------
n_noise_elem=nel_noise(fp_in, major_line_status[20], err_index, fp_log);
noise_a_f_ph=calloc(3*n_noise_elem,sizeof(double));
pnoise_elem=calloc(n_noise_elem, ELNAME_LEN);
pnoise_elem=&noise_elem[0];
noise_block_reader(fp_in, major_line_status[20], major_line_status[22], n_noise_elem,
pnoise_elem, noise_a_f_ph, err_index, fp_log);