I need help. I keep getting a Bus Error when I run my program and I've narrowed down where it occurs to the following code fragment.
px0c0 and px0c1 are type double pointers and
count_x0c0[m] and countc0 are integers. Can anyone see why this code would be giving me a Bus Error? Thanks.

// set *px0c0 and *px0c1
for(int m=0;m<data.n;m++)
{
bayes.px0c0[m]=1.0 * (count_x0c0[m]/countc0);
bayes.px0c1[m]=1.0 * (count_x0c1[m]/countc1);
}

bayes.pc0 = 1.0 * countc0 / data.N;

>px0c0 and px0c1 are type double pointers
How's your allocation of memory to px0c0 and px0c1?

bayes.px0c0 = (double*) calloc(n, sizeof(double));
bayes.px0c1 = (double*) calloc(n, sizeof(double));

Then I have a for loop initialize all of them.

And n and data.n are the same? And is data.N a type for data.n?

what is a Bus Error?

thanks dave

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.