This is my code and i am getting a runtime error SIGSEGV. I understand that this is error occcurs due memory segmentation faults. But, i don’t unerstand what to change in my code to avoid that.
I do not recognise the problem you are trying to solve. I do notice that n[i] can be at most 5000. In clearlex, parameter t is therefore also at most 5000. After the loop, i can therefore be 5000. The statement lex[i]=lext[i]=’\0’; will then overrun the array boundary…
Two other observations:
It seems that you read in the test cases and then calculate the results. Your program may become simpler (and use less memory) if you read each test case and immediately calculate its result.
The statement c=(c+1)%1000000007 raises questions. This piece of code can be run at most 5000 times after c has been set to 0. The % operator will not have any effect. I guess there is some problem in the logic here…
Don’t forget to remove cin >> a before you submit the code…
This is an error caused by an invalid
memory reference or segmentation
fault. The most common causes are
accessing an array element out of
bounds, or using too much memory.
Some things for you to try:
Make sure you aren’t using variables that haven’t been
initialised. These may be set to 0 on
your computer, but aren’t guaranteed
to be on the judge.
Check every single occurrence of accessing an array element and see if
it could possibly be out of founds.
Make sure you aren’t declaring too much memory. 64 MB is guaranteed, but
having an array of size [10000][10000]
will never work.
Make sure you aren’t declaring too much stack memory. Any large arrays
should be declared globally, outside
of any functions - putting an array of
100000 ints inside a function probably
won’t work.
For me, most of the time the reason is - accessing array offset beyond the size of array.
EDIT - To track the SIGSEGV, you should run your program in gdb, or the debugger present in your IDE. The debugger stops at exact point of SIGSEGV, so you can examine the line of code just before that. You can also look at the call stack.