These lines of code:
long duration; duration = (long)(500*g_sampleTimeInSeconds) / 60; printf("Memory will fill up after %d minutes\n", duration); are producing a negative number when g_sampleTimeInSeconds is greater than 65. When g_sampleTimeInSeconds = 65 the printed number is 541 but when it is 66 the printed number is -542 rather then the correct number of 550. This is also the case when g_sampleTimeInSeconds is replaced with hardcoded values.
This code is compiled with the XC8 compiler to run on Microchip PICs
UPDATE:
g_sampleTimeInSeconds is an 16 bit int
(500L*g_sampleTimeInSeconds) / 60;l:printf("Memory will fill up after %ld minutes\n", duration);