Why do I get a SIGSEGV?

I am getting run time SIGSEGV error on submitting my solution, but it works well during test compile on codechef online ide .

c code is as follows:
https://www.codechef.com/viewsolution/15016628

Cant see code atm. Its giving me a blank whitepage in place of code with weird stuff written on it.

Your link is not displaying any code.Please include a solution code.
This error may be caused e.g. by an out-of-scope array index causing a buffer overflow, an incorrectly initialized pointer, etc. This signal is generated when a program tries to read or write outside the memory that is allocated for it, or to write memory that can only be read
eg) int a[100];//creating array of size 100;
But if I am trying to provide 1000 input there is a possible of these errors.

Your code is not running properly if you append a blank space at the end of each line of test cases. The below mentioned code gets affected when there is a blank space at the end of the test case line. Not sure, but this might be a reason.

while((scanf("%ld%1[^\n]s", &b[i], &discard)) == 2)
i++;

Approach: Try to take inputs on the basis of first character rather than relying on \n.

1 Like

It is visible now.Please tell me where I went wrong.

//