×

# Why do I get a SIGSEGV?

 6 1 Why I am getting a runtime error SIGSEGV in the problem? Where I am going wrong? asked 20 Mar '13, 17:03 417●19●25●31 accept rate: 50%

 19 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 bounds. 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. answered 20 Mar '13, 17:05 0★admin ♦♦ 14.9k●347●484●503 accept rate: 36% life saver! (06 Jul '16, 23:00) U can declare a array of size [10000][10000] globally . and it will not give sigsegv error (18 Aug '16, 03:44) yb4singh5★
 4 use static memory allocation ,not dynamic (y) this causes SIGSEVG error sometimes answered 05 Jan '16, 15:18 582●1●7 accept rate: 3%
 0 //why i was getting SIGSEGV?? //for this question http://www.codechef.com/COQU2014/problems/DCQ1402 //please help n explain for this solution http://www.codechef.com/viewsolution/5277974 answered 07 Nov '14, 17:01 1 accept rate: 0%
 0 why do i get SIGSEV for the problem http://www.codechef.com/KAN14ROL/problems/ACM14KN3/ answered 25 Nov '14, 20:07 2★gokul95 26●1 accept rate: 33%
 0 solution is http://www.codechef.com/viewsolution/5456719 answered 25 Nov '14, 20:08 2★gokul95 26●1 accept rate: 33%
 0 why am i getting sigsev for the solution at http://www.codechef.com/viewsolution/5601458 answered 15 Dec '14, 16:13 1 accept rate: 0% because you are initializing array a of size 5 , whereas n can be very large , so you are trying to access invalid memory hence SIGSEGV (15 Dec '14, 16:18)
 0 can anyone help m why m getting SIGSEGV RUNTIME ERROR http://www.codechef.com/viewsolution/5940071 answered 19 Jan '15, 23:20 0★visght 1 accept rate: 0% You have assumed that size of the array is 100 while it is given in the question that size can be up to 10^6. So in your for loop you will be accessing array out of bounds. (06 Feb '15, 07:32)

why di i get reutime error for given problem

# define size 65535

int main() { long n,k,j,t[size],i=0,count=0; scanf("%ld %ld",&n,&k); while(i<n) { scanf("%ld",&t[i]); printf("\n"); if(t[i]%k==0) count++; i++; } printf("%ld\n",count); }

1
accept rate: 0%

 0 please help why do i get sigsegv in this code http://www.codechef.com/viewsolution/5988352 answered 25 Jan '15, 12:57 1 accept rate: 0% You are creating character array of length of 50 to store the given string whose length can be equal to 50. Each character array used to store string("%s" format specifier) automatically adds null character('\0') in the end. So you actually need length+1 memory to store. (06 Feb '15, 07:36)
 0 why do i get SIGSEVG answered 04 Feb '15, 12:31 1★nikkey 1 accept rate: 0%
 0 why am i getting SIGSEVG ? http://www.codechef.com/viewsolution/6144778 plz help answered 07 Feb '15, 23:09 1 accept rate: 0% How do u declare array of unknown size?. so after taking the input, u have to declare .i.e int q[n]. below is my accepted solution with just change of one line in your code http://www.codechef.com/viewsolution/6348707 (25 Feb '15, 21:14)
 0 can anyone help me..why i am getting SIGSEVG error in this http://ideone.com/PeQwg9 thanks in advance answered 08 Feb '15, 16:03 2★ashubaba 1 accept rate: 0%
 0 can anyone help me..why i am getting SIGSEVG error in this http://ideone.com/PeQwg9 thanks in advance answered 08 Feb '15, 16:03 2★ashubaba 1 accept rate: 0%

# include<stdio.h>

main() { long long t=0,i=0,j=0,temp=0,a[10000]; scanf("%lld",&t); for(i=0;i<t;i++) scanf("%lld",&a[i]);

for(i=0;i<t-1;i++)
{
for(j=0;j<t-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
for(i=0;i<t;i++)
printf("%lld\n",a[i]);


}

1
accept rate: 0%

why am i getting SIGSEVG ? http://www.codechef.com/viewsolution/6368752 plzzzzz help me!! Thank U..

311
accept rate: 0%

Cant access!!

(01 Mar '15, 00:04)

Is it in python?

(01 Mar '15, 00:05)

no, it is c...this is the problem http://www.codechef.com/COCR2015/problems/COCR07/ and this the code

# include <stdio.h>

long long int a[1000006]; int main() { long long int n,k,i,co=0,max=0; scanf("%lld %lld",&n,&k); for(i=1;i<=n;i++) { scanf("%lld",&a[i]); if(max<a[i]) max="a[i];" }="" long="" long="" int="" c[max+1];="" for(i="0;i&lt;=max;i++)" c[i]="0;" for(i="1;i&lt;=n;i++)" c[a[i]]++;="" for(i="1;i&lt;k;i=i+2)" {="" if(c[i]="">0) co++; } printf("%lld\n",co); return 0; } thank u..

(05 Mar '15, 17:12)
 0 A segfault basically means you did something bad with pointers. This is probably a segfault: char c = NULL; ... c; // dereferencing a NULL pointer Or this: char *c = "Hello"; ... c[10] = 'z'; // out of bounds, or in this case, writing into read-only memory Or maybe this: char *c = new char[10]; ... delete [] c; ... c[2] = 'z'; // accessing freed memory Same basic principle in each case - you're doing something with memory that isn't yours. answered 01 Mar '15, 00:47 3★sharru05 519●3●20 accept rate: 14%
 0 Hi Folks, Check out the latest Coding jobs :- http://jobsiit.com/jobs/listing/Computer%20Science answered 01 Mar '15, 13:49 0★jobsiit 17●3 accept rate: 0%
 0 Adobe Systems is hiring Software Engineers CTC:- 8-30 Lac, Exp:- 0-8 Years, Bangalore Apply Here:- http://jobsiit.com/jobs/view/1876/Adobe-Systems/Software-Engineer answered 01 Mar '15, 14:00 0★jobsiit 17●3 accept rate: 0%
 0 Why do I get SIGSEGV error for this code http://www.codechef.com/viewsolution/6382701 answered 03 Mar '15, 01:36 1 accept rate: 0%
 0 Pls help me with the runtime error(SIGSEGV) http://www.codechef.com/viewsolution/6400340 answered 06 Mar '15, 01:30 1 accept rate: 0%
 0 Runtime Error(SIGSEGV) in codechef???? here is my code... http://www.codechef.com/viewsolution/6420544 answered 07 Mar '15, 17:56 2★ni123 1 accept rate: 0%
 0 Can you please tell why SIGSEGV error in this code. http://www.codechef.com/viewsolution/6454306 answered 10 Mar '15, 16:15 2★csix 1 accept rate: 0%
 0 http://www.codechef.com/viewsolution/6583655 why i m getting SIGSEVG?? plz help answered 27 Mar '15, 00:55 2★trolled 1 accept rate: 0%
 0 why am i getting SIGSEVG ? http://www.codechef.com/viewsolution/6845084 answered 07 May '15, 16:01 1 accept rate: 0%
 0 Why do I get SIGSEVG ? http://www.codechef.com/viewsolution/7075835 answered 04 Jun '15, 17:50 0★rohith_o 1 accept rate: 0%
 0 http://www.codechef.com/viewsolution/7240860 why I am getting sigsevg error answered 17 Jun '15, 13:24 1 accept rate: 0%
 0 Why do I get SIGSEGV error for this code http://www.codechef.com/viewsolution/7280734 Please help, I haven't used pointers or functions and it runs perfectly well on code blocks answered 25 Jun '15, 14:08 1 accept rate: 0%

# include<stdio.h>

int main() { int i,n,f=1,j=1; scanf("%d",&n); int a[10]; for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) {
f=1;j=1; while(j<=a[i]){
f=f*j; j++; } printf("%d\n",f); } return 0; }

why am i getting a run time error here?

1
accept rate: 0%

 0 Why I'm Getting SIGSEVG for this: https://www.codechef.com/viewsolution/7491075 answered 17 Jul '15, 04:20 0★ritj1211 1 accept rate: 0%
 0 Can anyone tell me why i am getting run time error(sigsegv) for this https://www.codechef.com/viewsolution/7491260 answered 17 Jul '15, 08:44 1 accept rate: 0%
 0 Just check if you are accessing any element outside the declared array size,most common error might be in a loop. answered 17 Jul '15, 17:33 37 accept rate: 0%
 0 I get runtime error, please check and give the answer https://www.codechef.com/viewsolution/8004579 answered 04 Sep '15, 20:58 2★suthirr 1 accept rate: 0%
 0 i got error "SIGSEGV" for my code https://www.codechef.com/viewsolution/8172487 answered 15 Sep '15, 15:26 0★asayed 1 accept rate: 0%
 0 Why am I getting SIGSEGV for this solution of the problem ADDMUL https://www.codechef.com/viewsolution/8210117 It is partially solved, still can someone explain why am i getting SIGSEGV answered 20 Sep '15, 19:30 3★devesh23 1 accept rate: 0%
 0 @devesh23 try to use less memory.. like try to solve the question using long int instead if long long int!! answered 20 Sep '15, 19:36 15●1●1●4 accept rate: 0%
 0 why am i getting SIGSEVG ? https://www.codechef.com/viewsolution/8450343 answered 08 Oct '15, 23:20 1 accept rate: 0%
 0 awesome question. answered 09 Oct '15, 15:11 4★ani310 1 accept rate: 0%
 0 why iam getting SIGSEVG ? This code is running successfully on the IDE. https://www.codechef.com/viewsolution/8704219 plz help answered 07 Nov '15, 00:55 1 accept rate: 0%
 0 Please check this https://www.codechef.com/viewsolution/8836252 , I've tried running it through codechef IDE and Codeblocks and it works fine. When I submitted what I get is a runtime error SIGSEGV. Thanks. answered 28 Nov '15, 16:05 1 accept rate: 0% aUtama[10] aCari[10] You are declaring maximum size as 10. However constraint on maximum size is sadly not specified. Set it to 10000 as that worked in many accepted solutions. (28 Nov '15, 16:28) vsp46★
 0 I got SIGSEVG error when my code compiled.In my code, I declared a 2D array of size N,and according to the constrains given in the problem ,N can be any integer upto 10^5,How do i overcome this ?? Please help me out. answered 11 Dec '15, 16:12 1 accept rate: 0%
 0 why do i get SIGSEVG ERROR please check this link https://www.codechef.com/viewsolution/8967541 answered 16 Dec '15, 22:56 0★aayush97 1 accept rate: 0%
 0 Why am I getting runtime error (SIGSEGV) I dont understand? https://www.codechef.com/viewsolution/9036347. Please help me anyone. answered 29 Dec '15, 11:18 1 accept rate: 0%
 0 why am i getting SIGSEVG ? https://www.codechef.com/viewsolution/9086051 Please help me anyone as soon as possible. answered 04 Jan '16, 18:34 1 accept rate: 0%
 0 Most of the questions in codechef have plenty of memory if you allocate it properly to the arrays. So, use it freely to declare large arrays. If you need more memory than needed, maybe you're taking the wrong approach. So, avoid using sigsegv and use plenty of memory. Please upvote if this helped you. answered 05 Jan '16, 19:22 3★aman935 110●1 accept rate: 0%

# include<stdio.h>

int main() { int t,n,v[10],i,j=0,big=0; static int c[10]; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&v[i]); ++c[v[i]]; } big=0; for(i=1;i<=n;i++) { if(c[i]>big) { big=c[i]; j=i; } c[i]=0; } printf("%d %d\n",j,big);

} return 0; }

1
accept rate: 0%

 0 HELP ME OUT FOR THIS RUN TIME ERROR SIGSEVG....HIGHLY IMPORTANT PLSS LINK: https://www.codechef.com/viewsolution/9410079 PLS PLS HELP ME OUT.. answered 13 Feb '16, 23:32 2★trail_ 1 accept rate: 0%
 0 i am getting an error please help me. My code is correct i checked it with codechef compiler also - https://www.codechef.com/viewsolution/9763053 answered 29 Mar '16, 12:11 1★nilayv12 1 accept rate: 0%
 0 What if we need to put an array of 100000 ints inside a function ? Rest everything is correct.But i m still getting SIGSEGV error:( answered 09 Apr '16, 00:05 1 accept rate: 0%
 0 https://www.codechef.com/viewsolution/9994477 why do i get SIGSEVG answered 03 May '16, 11:45 1 accept rate: 0%
 0 @thepranay14 you are getting segsigv because in question the upper limit of n i.e the number of elements in array p is 100000 but you are storing just 9997. when you got the value of n from stdin then it may contain a value of 100000 and your for loop will for(i=0;i

why do i get a runtime error sigsegv for this problem? pls help.

# include<stdio.h>

int main() { int k, n; while(n<=10000000&&k<=10000000) scanf("%d", &n); scanf("%d", &k); int t[n]; int i; while(i<n&&t[i]<=1000000000) { scanf("%d\n", &t[i]); i++; } int count = 0; for (i = 0; i < n; i++) { if (t[i] % k == 0) count = count + 1; } printf("%d", count); }

1
accept rate: 0%

 0 Why I am getting SIGSEGV error on TSORT problem. I am using C and here is my Solution answered 11 May '16, 20:13 1 accept rate: 0%

# include<stdio.h>

int main() { int r,i,j,k,l,p,q,x; int n,m,T; int B[n],A[n-m]; scanf("%d",&T); for(k=0;k<T;k++) { scanf("%d%d",&n,&m); for(r=0;r<n;r++) {B[r]=0; }

     for(l=0;l<m;l++)
{
scanf("%d",&x);
B[x-1]=1;
}

for(i=0,j=0; i<n,j<n-m; i++)
{
if(B[i]==0)
A[j++]=i+1;

}

for(q=0;q<n-m;q=q+2)
{printf("%d ",A[q]);
A[q]=0;
}
printf("\n");

for(p=0;p<n-m;p++)
{
if(A[p]!=0)
printf("%d ",A[p]);
}
printf("\n");

}
return 0;


}

why am i getting this error here????pls help

1
accept rate: 0%

 0 Why are my programs getting runtime error (SIGSEV) during submissions but run well in all IDEs I've tried? I'm pretty sure it's not a case of out-of-range array access. What are the other possible faults? answered 28 May '16, 14:57 1●1 accept rate: 0%
 0 please check this this code works fine on codechef ide ,ideone.com but every time when i am submitting i am getting runtime error SIGSEGV https://www.codechef.com/viewsolution/10443904 answered 11 Jun '16, 23:05 1●1●1 accept rate: 0%
 0 I do not quite understand why there are so many people have posted their own questions as answers for this question. Probably, this isn't well moderated or there is something that I do not understand. Since, there is no code provided in the question the reason for getting SIGSEGV could not be determined. I am surprised that this old thread has 61 answers when actually there is no relevant information. answered 12 Jun '16, 00:02 1 accept rate: 0%
 0 answered 12 Jun '16, 00:50 4★kvsk 31●1●2 accept rate: 0%
 0 why m getting SIGSEGV RUNTIME ERROR for problem https://www.codechef.com/problems/LCOLLIS solution is https://www.codechef.com/viewsolution/10610834 answered 26 Jun '16, 00:42 1 accept rate: 0%
 0 SIGSEV error pops up due to a segmentation fault Possible reasons for segmentation fault are : One of the array indices you used would've been an invalid index . This means that at some point of execution , your program uses a value for the array index that is either more than the size of the array or less than 0 When you try to dereference a pointer with NULL value When you declare an array of a very huge size . In this case the compiler itself can't handle the array . Hence it pops out segmentation fault Try adhering to all of the specifications as mentioned by the admin Also , this link may help you answered 26 Jun '16, 23:25 1 accept rate: 0%

getting SIGSEV onthis piece of code which is from the beginner fctrl problem

# include<iostream>

using namespace std; int main() { int num,n=1,zeroes=0,power=5; cin>>num; int i,j,k,arr[1000],res[1000]; for(i=0;i<num;i++) {="" cin="">>arr[i]; } for(j=0;j<num;j++) {="" zeroes="0;" power="5;" while((arr[j]="" power)="">0) { zeroes+=(arr[j]/power); n++; power*=5; } res[j]=zeroes; } for(k=0;k<num;k++) cout<<res[k]<<endl; return 0; }

please help tried to write a very precise piece of code but it seems not to be working help;

2★vannjot
1
accept rate: 0%

why do i get SIGSEVAG for this code ?

# include<bits stdc++.h="">

using namespace std; int main(){ int t; cin>>t; while(t--){ int m,n,i,indices,count=0; cin>>n>>m; int a[n]={0}; while(m--){ cin>>indices; a[indices-1]=1; }

      for(i=0;i<n;i++){
if(a[i]!=1){

count++;
if(count%2==0&&count!=0)
a[i]=3;
if(count%2==1)
a[i]=4;
}
}

for(i=0;i<n;i++){
if(a[i]==4)
cout<<i+1<<" ";


} cout<<endl; for(i=0;i<n;i++){

        if(a[i]==3)
cout<<i+1<<" ";
}
cout<<endl;
}
return 0;


}

1
accept rate: 0%

 0 @vineeta1995 .Condition if(t[I]℅k==0) Will give run time error if value of k=0; answered 07 Jul '16, 03:00 1 accept rate: 0%
 0 @ankittt_jain you have declared array a[n] If the value of n goes above 10^6 then you will get run time error. answered 07 Jul '16, 03:13 1 accept rate: 0%
 0 You can check here for all errors that mostly occurs at codechef https://www.codechef.com/wiki/status-codes SIGSEGV : A SIGSEGV is an error(signal) caused by an invalid memory reference or a segmentation fault. You are probably trying to access an array element out of bounds or trying to use too much memory. Some of the other causes of a segmentation fault are : Using uninitialized pointers, dereference of NULL pointers, accessing memory that the program doesn’t own answered 14 Jul '16, 10:10 3★sau1999 65●1●4 accept rate: 0%
 0 You are getting SIGSEGV becuase you have take character pointer char a and inputting directly into "a" by using scanf("%s",a); This is wrong. "a" is a pointer and has no memory alocated to it. You should first allocate memory to the pointer using malloc before taking inout. a=(char )malloc(sizeof(char)*SIZE) where SIZE is the maximum input lenght of string + 1(1 extra for '\0'). Just add this line before your scanf line. answered 16 Jul '16, 20:28 11●1 accept rate: 0%
 0 I have tried many things and this code runs fine on my computer but on submitting I repeatedly get SIGSSEVG ?? You can check here.https://www.codechef.com/viewsolution/10845863 answered 17 Jul '16, 15:12 1 accept rate: 0%
 0 why do i get sigsevg for this code https://www.codechef.com/viewsolution/11028794 link This answer is marked "community wiki". answered 05 Aug '16, 20:48 0★anmolh12 1 accept rate: 0%
 0 why do i get sigsevg for the code : https://www.codechef.com/viewsolution/11028794 answered 05 Aug '16, 20:50 0★anmolh12 1 accept rate: 0%
 0 Go to Help---> FAQ You get most of your answer there. 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 bounds. 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. answered 13 Aug '16, 23:07 2★yado 1 accept rate: 0%
 0 As wikipedia says "It is an fault raised by hardware informing your operating system about memory access violation , for which os kernel in return generate a signal to the offending process , called SIGSEGV (or Core dumped)." But in simple terms "These errors are generated if any pointer(like in C language that provide low level memory access) is trying to access a memory location which has not been allocated to the program , or your program is trying to use memory which are not for the program " answered 14 Aug '16, 09:31 3★alphaguy 16●1 accept rate: 16%
 0 getting runtime SIGSEVG on this, don't know why https://www.codechef.com/viewsolution/11194997 answered 17 Aug '16, 16:58 1 accept rate: 0%
 0 why am i getting SIGSEV for this solution? https://www.codechef.com/viewsolution/11203458. what can i really do in order to remove it? answered 19 Aug '16, 01:10 2★nikseddu 1 accept rate: 0%
 0 i am getting sigsegv in this code https://www.codechef.com/viewsolution/11221046 for this problem https://www.codechef.com/problems/TSORT pls help answered 21 Aug '16, 13:23 0★ayesha_j 1 accept rate: 0%

# include<stdlib.h>

int main(int argc,char * argv[]) {
int i,j,m, T,reverse=0; // int arr[200]; int n[200]; T=atoi(argv[1]) ; if(!((1<=T)&&(T<=1000))) { exit(0); //checking if T is not greater than 1000 and not less than 1 } for(i=0,j=2;j<T+2;i++,j++) { n[i] = atoi(argv[j]) ; if(!((1<=n[i])&&(n[i]<=100000) )) //checking if n is not greater than 100000 and not less than 1 { exit(0); //(0 <= i) && ( i<=10) } } /* printf("%d\n",T);

for(m=0;m<T;m++)
{
printf("%d\n",n[m]);
}
*/

for (m=0;m<T;m++)
{
reverse=0;
while(n[m] != 0)
{
reverse = reverse * 10;
reverse = reverse + (n[m] % 10 );
n[m] = n[m] / 10;
}
//printf("%d\n",n[m]);

printf("%d\n",reverse);

}


return 0;
}

why m getting sigsegv

1
accept rate: 0%

# include<stdlib.h>

int *intArray,n ;

void display(){ int i; // navigate through all items for(i = 0;i<n;i++){ printf("\n%d ",intArray[i]); } }

void swap(int num1, int num2){ int temp = intArray[num1]; intArray[num1] = intArray[num2]; intArray[num2] = temp; }

int partition(int left, int right, int pivot){ int leftPointer = left -1; int rightPointer = right;

while(1){

  while(intArray[++leftPointer] < pivot){
//do nothing
}

while(rightPointer > 0 && intArray[--rightPointer] > pivot){
//do nothing
}

if(leftPointer >= rightPointer){
break;
}else{
swap(leftPointer,rightPointer);
}


} swap(leftPointer,right); return leftPointer; }

void quickSort(int left, int right){
if(right-left <= 0){ return;
}else { int pivot = intArray[right]; int partitionPoint = partition(left, right, pivot); quickSort(left,partitionPoint-1); quickSort(partitionPoint+1,right); }
}

int main(){ int i; scanf("%d",&n); intArray=(int*)calloc(n,sizeof(int)); for(i=0;i<n;i++) scanf("%d",intArray[i]); quickSort(0,n-1); display(); free(intArray); return 0; } questions:-- All submissions for this problem are available.

Given the list of numbers, you are to sort them in non decreasing order. Input

t – the number of numbers in list, then t lines follow [t <= 10^6]. Each line contains one integer: N [0 <= N <= 10^6]

Output

Output given numbers in non decreasing order. Example

Input:

5 5 3 6 7 1 Output:

1 3 5 6 7 why i am getting fragmentation error.?

2★ganesh5
292
accept rate: 0%

 0 why am i getting SIGEGV for this program https://www.codechef.com/viewsolution/11453342 answered 09 Sep '16, 20:37 1 accept rate: 0%
 0 whats wrong in this code. can some one help me out https://www.codechef.com/viewsolution/11554582 answered 18 Sep '16, 17:44 1 accept rate: 0%
 0 answered 23 Sep '16, 12:56 1★nk01 1 accept rate: 0%
 0 somebody please upvote me , i have questions to ask thank you answered 25 Sep '16, 16:43 124●3 accept rate: 4%
 0 This Error is related to Size of Array The size of Array shall be 'equal to or more than the no. of possible cases'. eg: if there are 50 possible cases, maybe it's not practical but your array size should be 50 or more. At the same time, the Array size shall not be impractically large. eg: A[1000000] will definitely give an Error. Sometimes Dynamic Memory Allocation may also give this error. link This answer is marked "community wiki". answered 04 Oct '16, 22:30 1 accept rate: 0%
 0 plzz help y i m gtting SIGSEVG in this code https://www.codechef.com/viewsolution/11774988 answered 11 Oct '16, 00:17 2★siddhi96 1 accept rate: 0%

# include<stdio.h>

void main() { int n,j; int flag=0,i=0; int green[10],yellow[10],red[10],r_t=0,y_t=0,g_t=0; scanf("%d",&n); for(j=0;j<n;j++) { for(i=0;i<3;i++) scanf("%d %d %d",&green[i+j],&yellow[i+j],&red[i+j]);

}
for(j=0;j<n*3;j++)
{

g_t=g_t+green[j];
y_t=y_t+yellow[j];
r_t=r_t+red[j];
}
if(g_t/2!=0 && y_t/2==0 && r_t/2==0)
{
printf("%d",g_t);
flag=1;
}
else{
if(g_t/2==0 && y_t/2!=0 && r_t/2==0)
{
printf("%d",y_t);
flag=1;
}
else{
if(g_t/2==0 && y_t/2==0 && r_t/2!=0)
{
printf("%d",r_t);
flag=1;
}
}
}
if(g_t/2!=0 && y_t/2!=0)
{flag=1;
if(g_t>y_t)
printf("%d",g_t);
else
printf("%d",y_t);
}
else{

if(g_t/2!=0 && r_t/2!=0)
{flag=1;
if(g_t>r_t)
printf("%d",g_t);
else
printf("%d",r_t);
}
else
if(y_t/2!=0 && r_t/2!=0)
{flag=1;
if(y_t>r_t)
printf("%d",y_t);
else
printf("%d",r_t);
}
}
if(flag==0)
{
printf("0");
}


}

1★pranit10
1
accept rate: 0%

 0 can we create 2d array of 100000*100000 arr[100000][100000] answered 12 Nov '16, 06:17 4★arpit147 1 accept rate: 0%
 0 Why I am getting SIGSEGV. https://www.codechef.com/viewsolution/12148465 answered 28 Nov '16, 00:19 0★naman00b 1 accept rate: 0%
 0 Why am I getting a SIGSEVG for this code , https://www.codechef.com/viewsolution/12256606 Please help! answered 11 Dec '16, 21:23 2★mishi8 1 accept rate: 0%

# include<stdio.h>

int main() { long long int t,n,i,j,m,max,k,r; scanf("%lld",&t); while(t--) { scanf("%lld",&n); long long int a[n][n],p[n]; for(i=1;i<=n;i++) { for(j=1;j<=n;j++) a[i][j]=0; } for(i=1;i<=n;i++) scanf("%lld",&p[i]); r=n-1; for(i=1;i<=r;i++) { scanf("%lld%lld",&m,&n); a[m][n]=1; } for(i=1;i<=n;i++) { max=0; for(j=1;j<=n;j++) { if(i!=j) { if(a[i][j]==0 && a[j][i]==0) {

                            k=p[j];
if(k>max)
max=j;
}
}
}
printf("%  lld ",max);
}
}


return 0; } where is the error

1★shakku
-1
accept rate: 0%

WHY DO I GET Runtime Error(SIGSEGV) FOR THIS SOLUTION OF PROBLEM:https://www.codechef.com/problems/MIME2

# include <bits stdc++.h="">

using namespace std; string s3,ans; int main() { int n,q; cin>>n>>q; string s1[n],s2[q]; for(int i=0;i<n;i++) {="" cin="">>s1[i]>>s2[i]; } while(q--) { ans=""; cin>>s3; int x=s3.length(); int i=0; while(s3[x-i-1]!='.') { if(i==(x-1)) break; i++; } if(s3[x-i-1]=='.') { while(i>0) { i--; ans+=s3[x-i-1]; } } int flag=0; for(int j=0;j<n;j++) { if(s1[j]==ans) { flag=1; cout<<s2[j]<<endl; break; } } if(flag==0) cout<<"unknown"<<endl; } }

1
accept rate: 0%

 0 @naman00b its because of condition for(i=1;i<=t;i++). Problem states that t is number of integers in number Now, in an array, numbers are indexed from 0 to n-1. Meaning, the first number has index 0, second has index 2...and hence n has index n-1. In final iteration, it makes a reference to index n, for which array size should had been n+1. But since array is of size n, its' maximum index is n-1. So when it calls for index n, it gives fault (PS: Please upvote if you find the explanation correct and good ^_^ ) answered 23 Jan, 19:02 3★vijju123 5.1k●2●11 accept rate: 17%
 0 @shakku If you can post the problem statement too, I can help. But seeing code, I suspect n is number of elements in array. Now - for(i=1;i<=n;i++) { for(j=1;j<=n;j++) a[i][j]=0; In every loop, you made index from 1 to n. But array has indexes from 0 to n-1. Try changing that 1 to n, to 0 to n-1. (If my answer helps, please upvote ^^) answered 23 Jan, 19:04 3★vijju123 5.1k●2●11 accept rate: 17%
 0 @bajajyukta If you can give your submission link, I can have a better look over the code. :) answered 23 Jan, 19:07 3★vijju123 5.1k●2●11 accept rate: 17%
 0 Somebody please help me with this solution. It works on my machine. But gives a SIGSEGV error here. P.S. My compiler is in compliance with C99. answered 12 Apr, 17:32 1 accept rate: 0%
 0 How to improvise in my code so as to remove SIGSEVG? Please check in this link https://www.codechef.com/viewsolution/13344516 answered 17 Apr, 07:47 1 accept rate: 0%
 0 Why am i getting sigsegv in this code https://www.codechef.com/viewsolution/13362815 Plz help me. answered 21 Apr, 00:14 1 accept rate: 0%
 0 why do i get sigsev for https://www.codechef.com/viewsolution/13419475 Really need help.. answered 30 Apr, 21:59 0★priyum7 1 accept rate: 0%
 0 Please tell me why am I getting SIGSEGV error for this beginner problem of Malvika's Fibonacci series. View my solution link text answered 18 May, 16:43 0★hs33 1 accept rate: 0%

I am Getting SIG SEVG error for this solution

# include<ctype.h>

int trim(char*);

int main(int argc, char** argv) {

int test_Cases, i = 0;

char input[10];

scanf("%d", &test_Cases);

while(i < test_Cases) {
scanf("%s", input);

if(trim(input) == 1)
puts("yes");
else
puts("no");

i++;


}

return 0;


}

int trim(char* s) {

int i =0, j = 0;

while(*(s+i) != '\0') {
if(toupper(*(s+i)) == 'C' || toupper(*(s+i)) == 'S' || toupper(*(s+i)) == 'E') {
*(s+j) = *(s+i);
j++;
}
i++;
}
*(s+j) = '\0';

i = 0;

while(i < strlen(s) - 1) {
if(s[i] > s[i+1])
return 0;
i++;
}

return 1;


} Can you tell me why ?

1
accept rate: 0%

 0 Hi. Please help me with understanding the SIGSEGV error here. Read the thread and some articles, still could not get the issue with the code. Question: https://www.codechef.com/problems/SIMDISH My solution: https://www.codechef.com/viewsolution/13712103 A similar accepted solution:https://www.codechef.com/viewsolution/13384645 My solution compiles, runs and gives me the correct answer in cmd compiler, but shows the run time error in codechef answered 22 May, 11:25 1 accept rate: 0%
 0 https://www.codechef.com/viewsolution/13938926 why do I get Runtime Error(SIGSEGV) to this code? link This answer is marked "community wiki". answered 01 Jun, 08:09 0★mojab 1 accept rate: 0%
 0 https://www.codechef.com/viewsolution/14108863 can anybody pls tell,why am i getting sigsegv error here?it would be a great help. Question : https://www.codechef.com/JUNE17/problems/CLONEMEa THnaks answered 06 Jun, 17:33 2★akriti17 1 accept rate: 0%
 0 hello everyone, I have recently shifted from C to C++, can someone please tell me why I'm getting sigsegv despite, it runs fine on Dev C++ ide. Please tell me which should I choose C++(4.9.2),(4.3.2) or 14. https://www.codechef.com/viewsolution/14296827 answered 20 Jun, 16:17 1 accept rate: 0%
 toggle preview community wiki
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Tags:

×222
×166
×51