gpt4 book ai didi

c - 段错误 11 - C

转载 作者:行者123 更新时间:2023-11-30 18:12:00 25 4
gpt4 key购买 nike

我不明白为什么这段代码返回段错误。谁能帮我告诉我出了什么问题吗?

#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 mu\n");
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 %lf\n", 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 %lf\n", t,
x[0],x[1],x[2],x[3],x[4],x[5]);
}
}
return 0;
}

在顶部,我复制了我使用的函数的原型(prototype),但它们可以工作,所以它们不是问题。

谢谢!

最佳答案

行中:

printf("%lf %lf %lf %lf %lf %lf %lf\n", t, 
x[0],x[1],x[2],x[3],x[4],x[5]);

它看起来好像t 没有被初始化。不确定这是否是原因,但您可以尝试初始化它,看看是否遇到同样的问题。

double t=0.0,x[N],h,mu,T;

如果这不是原因,那么我实际上会开始怀疑您信任的功能!

关于c - 段错误 11 - C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42237301/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com