Are you compiling with c99 or c89?
The error appears to be because you are defining a variable within the body of the function (allowed in c99 not c89). Move double *ptr to the beginning of the function and then just assign ptr = mat->matrix; where the error now is.