Someone please see my code at this link for input taken from this file( 2.2 mb file). This produces seg fault. By gdb, it shows seg fault in _vfprintf_r(). But when I comment line 41 and uncomment 38 (a null statement), there is no segmentation fault. line no 41 is just print statement. Someone please help. I am frustated and wasted a day in debugging. The output is written into result.txt file.
You have a stack overflow. That's right, a Stack Overflow. I was able to reproduce by doing ulimit -s 1024. You need to not recurse so deeply, or you need to increase your stack size.