Hi, folks,
I have a question about structure array as a argument.
The below short program is that main function call a subroutine
which increases real and imaginary part by 1 respectively in
complex numbered structure array.
There is no error when it is compiled.
But when it is running, it has a segmentation fault.
I guess I made a mistake when main passes the matrix to subroutine.
But I don't know how.
Please, help me out a trouble!
Thanks,
Chang
************************************************** ************
#include <stdio.h>
#include <stdlib.h>
typedef struct DCOMPLEX{double r,i;}dcomplex;
void inc_mat(dcomplex **);
void main()
{
int ii,kk;
dcomplex mat[4][4];
for(ii=0;ii<4;ii++){
for(kk=0;kk<4;kk++){
(*(*(mat+ii)+kk)).r=ii;
(*(*(mat+ii)+kk)).i=kk;
}
}
inc_mat(mat);
}
void inc_mat(dcomplex **mata)
{
int ii,kk;
printf("mata=%d\n",mata);
for(ii=0;ii<4;ii++){
for(kk=0;kk<4;kk++){
(mata[ii][kk]).r +=1;
(mata[ii][kk]).i +=1;
}
}
}