编译通过后,运行时出现问题?
运行时,出现下面的错误信息:Error while dumping state<probably corrupted stack>
Segmentation fault <core dumped>
麻烦看一下哪里有问题。另外,我用的是GCC。谢谢。
#include <stdio.h>
#include <math.h>
main()
{
int idum, k,s;
double sigmae,sigmat;
double *mu, *u, *sigm,*sigmt;
double *vector(), ran1(), gasdev();
printf("Enter group number s:");
scanf("%d",&s);
sigmae=0.0;
sigmat=0.0;
sigm=vector(0,s);
sigmt=vector(0,s);
for (k=0; k<s; k++)
{idum=-10*k*k-2+k;
mu[k]=0.0; u[k]=0.0; sigm[k]=0.0;
sigm[k]=sigmat+ran1(&idum)*(1.5-sigmat);
u[k]=sigm[k]*gasdev(&idum);
mu[k]+=u[k];
}
}
/* *************** VECTOR.C ********** */
double *vector(nl, nh)
int nl, nh;
{ double *v;
v = (double *)malloc((unsigned) (nh-nl+1) * sizeof(double));
return v-nl;
}
/* ***************** NORMAL RANDOM GENERATOR: GASDEV.C *********** */
double gasdev(idum)
int *idum;
/* returns a normally distributed deviate with mean 0
and variance 1, using ran1(idum) as the source of uniform
deviates */
{
static int iset=0;
static double gset;
double fac,r,v1,v2;
double ran1();
if (iset == 0) {
do {
v1=2.0*ran1(idum)-1.0;
v2=2.0*ran1(idum)-1.0;
r=v1*v1+v2*v2;
} while (r >= 1.0 || r == 0.0);
fac= sqrt(-2.0*log(r)/r);
gset=v1*fac;
iset=1;
return v2*fac;
} else {
iset=0;
return gset;
}
}
/* ******************** UNIFORM RANDOM NUMBER GENERATOR: RAN1.c ******* */
#include <stdlib.h>
#define M1 259200
#define IA1 7141
#define IC1 54773
#define RM1 (1.0/M1)
#define M2 134456
#define IA2 8121
#define IC2 28411
#define RM2 (1.0/M2)
#define M3 243000
#define IA3 4561
#define IC3 51349
double ran1(idum)
int *idum;
/* returns a uniform random deviate between 0.0 and 1.0.
Set idum to any negative value to initialize or
reinitialize the sequence */
{
static long ix1,ix2,ix3;
static double r[98];
double temp;
static int iff=0;
int j;
void nrerror();
if (*idum < 0 || iff == 0) {
iff=1;
ix1=(IC1-(*idum)) % M1;
ix1=(IA1*ix1+IC1) % M1;
ix2=ix1 % M2;
ix1=(IA1*ix1+IC1) % M1;
ix3=ix1 % M3;
for (j=1;j<=97;j++) {
ix1=(IA1*ix1+IC1) % M1;
ix2=(IA2*ix2+IC2) % M2;
r[j]=(ix1+ix2*RM2)*RM1;
}
*idum=1;
}
ix1=(IA1*ix1+IC1) % M1;
ix2=(IA2*ix2+IC2) % M2;
ix3=(IA3*ix3+IC3) % M3;
j=1 + ((97*ix3)/M3);
if (j > 97 || j < 1) nrerror("RAN1: This cannot happen.");
temp=r[j];
r[j]=(ix1+ix2*RM2)*RM1;
return temp;
}
/* *********************NRERROR.C ******************** */
void nrerror(error_text)
/* prints an error message */
char error_text[];
{
fprintf(stderr,"Numerical recipes run-time error...\n");
fprintf(stderr,"%s\n",error_text);
fprintf(stderr,"...now exiting to system...\n");
exit(1);
}