Arduino getting reset after at a certain point

I am trying to log the values received from GPS to SD card. For this I am using UTFT and tinyFAT libraries. In program A I am printing the values received from GPS on the console without any issues. In B I am writing 1024 lines to a file created in the SD card. In C however, when I am trying to write the values received from GPS to the SD card, Arduino is restarting after it has written 316 values to the SD card. I am not able to figure out why is this happening when both things are working separately in sketch A and B. Thanks. I am using Arduino Mega 2560.

A.ino (2.47 KB)

B.ino (1.48 KB)

C.ino (4.17 KB)

Where is sketch A, where is sketch B, where is sketch C.

Without further information, try checking line 97.

And, which Arduino are you using. I'd guess that the 2 terrabytes of memory that you think you have doesn't match reality.

Sorry everyone, I don't know how I missed attaching the files. Added now.

What about the Arduino? How much memory does it have? Of that, how much are you using?

http://playground.arduino.cc/Code/AvailableMemory