float **matrix(long nrl, long nrh, long ncl, long nch)
/* allocate a float matrix with subscript range m[nrl..nrh][ncl..nch] */
long i, nrow=nrh-nrl+1, ncol=nch-ncl+1;
/* allocate pointers to rows */
m=(float **) malloc((size_t)((nrow+NR_END)*sizeof(float*)));
nrerror("allocation failure 1 in matrix()");
m += NR_END;
m -= nrl;
/* allocate rows and set pointers to them */
m[nrl]=(float *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(float)));
nrerror("allocation failure 2 in matrix()");
m[nrl] += NR_END;
m[nrl] -= ncl;
/* return pointer to array of pointers to rows */
the program is correct, becuase i took it form a book.i call this function with this program:
and it shows this error:
First-chance exception at 0x008e50a4 in lfit2.exe: 0xC0000005: Access violation reading location 0xcdcdcdd1.
Unhandled exception at 0x771115de in lfit2.exe: 0xC0000005: Access violation reading location 0xcdcdcdd1.
i dont know if this information is enough or i should put here whole program which is so long. if you need to see whole program please let me know.
The cdcdcd.. pattern suggests you're trying to use a bit of unititlialized heap memory as the variable for a memory address.
Have you run your code under the debugger to see which line is blowing up? (The debug build should stop at the line where things go wrong, if you're using a debugger.)
Note that you program is trying to access memory ranges which are inaccessible to normal "user mode" apps, where I'm assuming you're using a normal 32-bit Windows PC. In that case, apps can only see address from 0x00000000 through to 0x7FFFFFFF (unless specifically configured to increase the upper limit).
The address 0xcdcdcdd1 is in the range reserved for "kernel mode" (used by device drivers and the lower level parts of the o/s).
PS For fill patterns, see (e.g.) the "Magic debug values" section of: