How to remove Runtime SIGTSTP error?

I wrote the following programme which will store the occurrence of every letter of a string in an array and upon seeing a letter repeated , it will take the data from previous element of array.

Here is the code.

On running it on different ide, some are showing segmentation fault or SIGTSTP error. Can anyone please tell me what is the error ?

5 Likes

Segmentation fault occurs when a program attempts to access a memory location that it is not allowed to access(eg: reading array elements over its limit )
Look at the constraints on inputs and then typecast the variables according to contraints.

3 Likes

It’s not segmentation fault seg fault it SIGSEGV
This one is when your code gets suspended due to illegal operation like decrementing an unsigned variable beyond zero, etc

13 Likes

hlo bro can you give your any socail media id

try using

#include< stdio.h>

module
and use scanf for input values

2 Likes

why is this code showing SIGTSTP…code
thanks!

Make sure you have given custom input

4 Likes

You messed Up ig.
In line 19: for(k=0;k<d;i++)
It works fine with --> for(k=0;k<d;k++)

In your code :
variable k is not updated in the for loop.
Also variable i is updated so it goes greater than d and in line 30 of your code it goes out of bound.

19:15: warning: variables 'k' and 'd' used in loop condition not
      modified in loop body [-Wfor-loop-analysis]
                for (k = 0; k < d; i++)
1 Like

Your code goes into infinite loop and results in Runtime error.

Compile using right flags to see warning.

1 Like

#include<stdio.h>
int main()
{
long int testcases ;
scanf("%li",&testcases);
long long int n,k,i=0;
//scanf("%llu %llu “,&n,&k);
while(testcases–)
{ int flag = 1;
scanf(”%llu %llu “,&n,&k);
long long int sum=0,a;
for( i=0 ;i<n;i++)
{
scanf(”%lld",&a);
sum+=a-k;
//printf(" %lld “,sum);
if(sum<0)
{
sum = i+1;
break;
}
}
if(flag=1)
printf(”%lld",(n+a/k));
else
printf("%lld",sum);
}
}

this is my code for the problem CHEFEZQ
This worked for me ,in my compiler but when i compiled it in codechef it came run time error

can anyone help me out with this

i got SIGTSTP error

it will be while(testcases–>0)
your while loop is iterating for infinite times because you haven’t put any limit .

I am facing the same error. I cannot find where this runtime error is coming. It would be great if someone could pinpoint the error.
Link to my code: Code

That’s a WA (Wrong Answer), not a Runtime Error (RE) :slight_smile:

Edit:

thanks, good explanation