Why my do/ while loop repeats 2 times before it checks condition?
int main() {
char quit;
quit = getchar();
do {
printf("Next state: ");
clock_t start = clock();
count_values(a, b);
clock_t end = clock();
float seconds = (float)(end - start) / CLOCKS_PER_SEC;
print_state(b);
printf("\nTime: %f\n", seconds);
swap(a, b);
printf("Press enter to print next generation. To quit, enter 'q'.");
quit = getchar();
} while(quit != 'q');
return 0;
}
Only after loop has repeated 2 times, getchar() waits for input, why? How to fix it?