I require the current date and time to be logged for my application. I have written the code in C. I have attached the code
#include <stdio.h>
#include <time.h>
int main()
{ time_t t;
while(1)
{ time(&t);
printf("Today's date and time : %s",ctime(&t));
}
}
The output is
Today's date and time : Wed Dec 31 23:59:59 1969
Today's date and time : Wed Dec 31 23:59:59 1969
Today's date and time : Wed Dec 31 23:59:59 1969
Today's date and time : Wed Dec 31 23:59:59 1969
The time is not getting updated since the start of the UNIX time. I ran the same program in another computer and it ran just fine. Why do I get this error in my computer and How do i resolve it?
Thank you
Any help appreciated.
EDIT: There was a mistake in the code, I rectified it so that the time is updated within the while loop