I'm trying to make a short puzzle game that plays in the terminal, but want to use delays to make dialogue work better. The delays are happening, however they're all happening at once, and the print statements are happening at the same time as well.
#include
#include
int wait(int seconds) {
time_t start;
time_t end;
time(&start);
end = start + seconds;
do {
time(&start);
} while(start < end);
return 0;
}
int main(void) {
system("clear");
printf("Hello there.\n");
wait(1);
printf("Do you want to play a game? (y/n)\n");
char answer;
scanf("%c", &answer);
system("clear");
if (answer == 'n' || answer == 'N') {
printf(".");
wait(1);
printf(".");
wait(1);
printf(".");
printf("\nUnderstood.\n");
return 0;
} else if (!(answer == 'Y' || answer == 'y')) {
printf("Answer found invalid.");
return 0;
}
printf("Very well.");
wait(1);
printf("\nLet's begin.");
return 0;
}
The problem is occurring when the block for inputting 'no' runs. I'm still messing with the delay to make sure it's as close to a second as possible, but even with it not being perfect I can tell that it's happening all at once, and then it just prints "..." instead of them one at a time. I'm pretty new to coding and don't know why this is happening.