So I have this program:
Code:
#include <stdio.h>
#include <stdint.h>
#define INTERVAL 24
int main()
{
int i, n;
printf("This program prints a table of squares. \n");
printf("Enter number of entries in table: ");
scanf("%d", &n);
for(i = 1; i <= n; i++)
{
printf("%5d% 5d\n", i, i * i);
if(i % INTERVAL == 0)
{
printf("\nPress enter to continue. ");
// This loops gets skipped because of the new line character that gets left behind once the user inputs something to the variable n
while(getchar() != '\n')
{
printf("\nYou must press the enter key. ");
getchar();
}
}
printf("\n");
}
return 0;
}
and the only thing wrong with it is that the while loop doesn't run because of the newline that gets left behind once the user enters characters to the variable n. I know a couple of workarounds to get around this but those methods aren't very stable and more short term than long term. So how would I properly dispose of this pesky newline character?