SIGABRT error

What could be the line that can cause SIGABRT error in this prog???
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
long int *b,l=0,i,j,k=2;
long int n,m;
system("CLS");
cin>>n>>m;
long int a[m],y[m];
b=new long int[n];
for(i=0;i<n;i++)
{
if(i<m)
{
cin>>a[i];
}
b[i]=0;
}
b[0]=1;
for(j=0;j<m;j++)
{
y[j]=a[j];
while(y[j]<n)
{
b[y[j]]++;
y[j]=(a[j])*(k);
k++;
}
k=2;
}
for(j=0;j<n;j++)
{
if(b[j]==0)
{l++;}
}
cout<<endl<<l;
system("PAUSE");
return 0;
}
long int a[m],y[m];
Variable length arrays are forbidden on the stack in C++. Your compiler shouldn't let you do this.

What input values do you give to cause the crash?
CLS on Unix? That won't cause a crash, but it won't do anything either. CLS is a builtin command in the DOS/Windows command line shell. You shouldn't be using system() in general.

If you use vectors instead of arrays, and replace [] with .at(), it'll tell you where it's going wrong. Plus you'll get variable sized containers.
@moschops, well the program gets crashed when the value of n>10^7
gimme a solution 2 this pls!
@kbw my OS isnt UNIX i use WINDOWS only!
@moschops, well the program gets crashed when the value of n>10^7
That would allocate an array of about 38 megebytes on the heap, which should be no problem.

What do you type AFTER the first value? What are ALL the inputs you use to cause the crash?
Last edited on
Topic archived. No new replies allowed.