inline void readSymColValUpdRow(int *row, const int nmat,
int **col, double **val, const int nnz,
FILE *fpcol)
{
*col = (int*)_mm_malloc(sizeof(int)*nnz, 64);
*val = (double*)_mm_malloc(sizeof(double)*nnz, 64);
FILE *fpval;
*fpval = *fpcol;
const int BUF_LEN = nnz*10;
char buf[BUF_LEN];
fgets(buf, BUF_LEN, fpval);
fgets(buf, BUF_LEN, fpval);
...//other code
}
Here's what I'm trying to do. I need two file pointers referring to different places in a file within the function "readSymColValUpdRow()". Thus I've declared a file pointer *fpval and assign the content of fpcol to it. "fpcol" is a valid file pointer passed by function parameter. I try to make fpval pointing two lines ahead. However, I always get "Segmentation fault" by doing so. Once I comment
*fpval = *fpcol;
and other relevant codes everything's just fine. I don't really understand what's going wrong here. Thank you for your help.
You are deferencing fpval and the variable is unitialized, this causes the segmentation fault. Also you cannot make a copy of the file pointer that way, you need to make a copy of the underlying file descriptor, for example:
fileno
will obtain the file descriptor,dup
will make a duplicate of it andfdopen
will open that file descriptor and create the new FILE pointer.Then close it after you are done with it.