I'm working on a project for school that prints 4 triangles after taking a size input and character from the user. I want to make a while loop that outputs an error message if the user inputs a value less than 1 or a character when they are asked what size they want the triangles to be. I was able to set up a loop that continues to prompt the user for an integer value if they enter something less than 1(shown here); but, if a character is entered the program goes into an infinite loop. Can anyone point me in the right direction on how to fix my while loop so that it doesn't go into a infinite loop if a character is entered?

Code:
#include <stdio.h>
#include<ctype.h>
void flush(void)
{
while (getchar()!='\n');
}
int main(void)
{
int size, i, j, valid_input;
char c, answer;
do
{
Printf(“enter triangle size \n”);
Scanf(“%i” ,&size);
while(size <= 0){
    printf("size must be greater than 0 \n");
    printf("\n");
    printf("enter triangle size \n");
    scanf("%i" ,&size);
    }
    flush();
Thanks in advance and sorry if my question isn't clear...been working on this problem all day and I am feeling a little