#include <stdio.h>
#include <time.h>
#include <stdlib.h>
usingnamespace std;
void wait ( int mseconds )
{
clock_t endwait;
endwait = clock () + mseconds;
while (clock() < endwait) {}
}
int main(){
int i = 1;
while(1){
if (i > 10) system("cls");
time_t *now;
struct tm *time_info;
time(now);
time_info = localtime(now);
printf("Current date/time: %s", asctime(time_info));
wait(1000);
i++;
}
return 0;
}
I compiled it with th MinGW C++ Compiler successfully, and ran it on Windows Command Prompt. However, it keep freezing up every time I run it, without even printing anything. I commented out all the stdlib.h lines:
Now it works, but without clearing the screen. Why is the program freezing when I use stdlib.h, and how can I do this without freezing up the program?
Thanks!
@kbw: thanks for that tip. I thought that if you declare time_t now as a pointer, you would not need to pass now by reference (just like struct tm *time_info). I changed my code to this: