I am programming an interpolation method to construct an spline to interpolate a data.
I have the file spline.c that contains three functions the one that allocates memory for the variable needed inside the interpolation method inimem_spline
and another function to free the space after computing the spline which is called freemem_spline
. But in this part I have an error:
argument of type
double
is incompatible with parameter of typevoid *
I don't know where this error come from.
#include "math.h"
#include "malloc.h"
#include "stdlib.h"
#include "stdio.h"
#include "subroutines.h"
// Libreria para resolver sistemas lineales.
static double *sub_diag, * sup_diag, *diag, *d ;
// Function which allocates memory for the variables used inside the interpolation method
void inimem_spline(int n)
{
int r = n-2, c = n-2;
int i, j;
d=(double *) calloc(n,sizeof(double));
if(d==NULL) {
printf("\ninimem_spline:It is not possible to allocate memory\n");
exit(19);
}
for(j=0;j<n;j++) d[j]=0.e+0;
sub_diag=(double *) calloc(n-1,sizeof(double));
if(sub_diag==NULL) {
printf("\ninimem_spline:It is not possible to allocate memory\n");
exit(20);
}
for(j=0;j<n;j++) sub_diag[j]=0.e+0;
sup_diag=(double *) calloc(n-1,sizeof(double));
if(sup_diag==NULL) {
printf("\ninimem_spline:It is not possible to allocate memory\n");
exit(21);
}
for(j=0;j<n;j++) sup_diag[j]=0.e+0;
diag=(double *) calloc(n,sizeof(double));
if(diag==NULL) {
printf("\ninimem_spline:It is not possible to allocate memory\n");
exit(22);
}
for(j=0;j<n;j++) diag[j]=0.e+0;
}
// Free Space of the Variables used inside the interpolation method.
void freemem_spline(int n)
{
int i,j;
for(j=0;j<n;j++) free(sub_diag[j]);
for(j=0;j<n;j++) free(sup_diag[j]);
for(j=0;j<n;j++) free(diag[j]);
for(j=0;j<n;j++) free(d[j]);
printf("\freemem_spline:Memmory free\n");
}
Remove the loops and simply
free(sub_diag);
free(sup_diag);
free(diag);
free(d);
Each free()
must correspond with each calloc()
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.