-1

The following code is a part of my user defined function in c

void genprime(long int m,long int n)
{

  long int j,k,p[10000]={0},c,c1,c2,r;

  int flag=0;
}

The function contains the logic to generate primes.I declared all variables type as long int as it was needed for high range.I am getting abnormal program termination message on execution.And when I declare all as int it is printing values but only for a specific range.Please help so that this can be resolved.Thanks in advance

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • The code you show can't crash, use a debugger to find out where the crash happens. – Some programmer dude Mar 20 '15 at 16:48
  • 1
    10000 long ints on a 64-bit machine is 80k. That's not much memory in general, but it might be more than what's available for stack allocation. Move `p` to a static, or allocate it with `malloc()`, and that will leave a more reasonably-sized stack. – Lee Daniel Crocker Mar 20 '15 at 17:16

1 Answers1

0

Try allocating the memory in the heap , long *p = malloc( 10000 * sizeof(long));

a_secenthusiast
  • 319
  • 3
  • 12