I have the following code, if I submit it to codechef with scanf function to read the inputs it works fine, if I submit it with the ReadFastInt16() function to read inputs I get a SIGSEGV error, I have used the ReadFastInt16() function in other codechef problems and it accept the solution but I don't know why is giving me segmentation fault now, could anyone help me?
ReadFastInt16 isn't nearly as robust as the scanf version (and will return some odd values if you begin with a non-digit in the input.) I doubt it would make much difference in most of the Code Chef problems as the format of input is usually pretty uniform, however any input where there were consecutive whitespace characters in the input stream will screw your function up. Have you tried changing it to something like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <cctype>
unsigned ReadFastInt16()
{
char digit = getchar();
while (std::isspace(digit))
digit = getchar();
unsigned n = 0;
while (std::isdigit(digit))
{
n = n * 10 + digit - '0';
digit = getchar();
}
return n;
}