It seems to me that the problem you have is that the last line in your file doesn't have a \n, so your code unexpectedly crashes out with the NULL test.

The lack of a final \n should not be a reason to crap out of the code with an exit failure.

Other than that, I just don't see any problem. The "Cannot access memory at address 0x0" is pretty obvious really, it's a NULL pointer. Just because you're using gdb, it doesn't buy you any magic.