我正在编程一种插值方法来构造样条曲线来插值数据。
我有一个文件spline.c,它包含三个函数,一个为插值方法inimem_spline
中所需的变量分配内存,另一个函数在计算出称为freemem_spline
的样条曲线后释放空间。但在这一部分,我有一个错误:
double
类型的参数与
void *
类型的参数不兼容
我不知道这个错误是从哪里来的。
#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 memoryn");
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 memoryn");
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 memoryn");
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 memoryn");
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 freen");
}
删除循环并简单地
free(sub_diag);
free(sup_diag);
free(diag);
free(d);
每个free()
必须与每个calloc()
相对应。