我不明白为什么此代码返回分割故障。有人可以帮我告诉我怎么了吗?
#include <stdio.h>
#include "rk78.h"
#include "flux.h"
#include "rtbps.h"
#define N 6
#define h0 0.1
#define pasmin 1E-6
#define pasmax 10
#define tol 1E-13
int rk78 (double *t, double x[], double *h,
double hmin, double hmax, double tol,
int n, int (*camp)(int n, double t, double x[], double f[], void *prm),
void *prm);
int flux (double *t, double x[], double *h, double T,
double pasmin, double pasmax, double tol, int npasmx,
int n,
int (*camp)(int n, double t, double x[], double f[], void *prm),
void *prm);
int rtbps (int n, double t, double *x, double *f, void *prm);
/*
Per compilar:
gcc -o rtbps_int -g -Wall rtbps_int.c rtbps.c flux.c rk78.c -lm
Executar:
./rtbps_int 1.215058560962404e-2 < halos_inp.txt > halos.txt
*/
int main (int argc, char *argv[]) {
double t,x[N],h,mu,T;
int i, nt;
if (argc!=2
|| sscanf(argv[1],"%lf",&mu)!=1
) {
fprintf(stderr, "./rtbps_int mun");
return -1;
}
/*
posició, velocitat, temps, iteracions
*/
printf("Ok");
while(scanf("%lf %lf %lf %lf %lf %lf %lf %d",
&x[0],&x[1], &x[2], &x[3],&x[4],&x[5],&T,&nt)==8){
printf("%lf %lf %lf %lf %lf %lf %lfn", t,
x[0],x[1],x[2],x[3],x[4],x[5]);
h=h0;
t=0;
for(i=1;i<=nt;i++){
//t=0;
flux(&t,x,&h,T/nt,pasmin,pasmax,tol,nt,N,rtbps,&mu);
printf("%lf %lf %lf %lf %lf %lf %lfn", t,
x[0],x[1],x[2],x[3],x[4],x[5]);
}
}
return 0;
}
在顶部,我复制了我使用的功能的原型,但它们可以工作,因此不是问题。
谢谢!
行:
printf("%lf %lf %lf %lf %lf %lf %lfn", t,
x[0],x[1],x[2],x[3],x[4],x[5]);
看起来好像t
是初始化的。不确定这是否是原因,但是您可以尝试初始化它,看看是否遇到了同样的问题。
double t=0.0,x[N],h,mu,T;
如果不是原因,那么我实际上会开始怀疑您信任的功能!