Added type cast for ctime function.
Fixed format problems and moved functions to avoid 'implicit declaration' warnings.