Copying an array into another one

I want to conditionally copy (only selected elements) from one array to a (big enough) empty one. I tried

1
2
3
4
5
int a=0;
int aarray[n+1];
  for(int i=1; i<n+1; i++)
    {if (r[i]<=800 && r[i-1]>800)
{ a++; aarray[a]=i;}

(where r[] is already filled up with n+1 numbers.
But it quits with SISEGV segmentation fault.
Last edited on
> r[] is already filled up with n numbers
But your loop goes to `n+1'
Sorry, it really is filled up with n+1 and it still raises the same thing.
variable length arrays (vla) are illegal in c++, use std::vector instead.
you may be running out of stack space.


If not, it's about time that you give a minimal snip that does reproduce your issue.
Topic archived. No new replies allowed.