I have the below code :

```
#include <stdio.h>

void printMenu() {
    printf("********************************\n");
    printf("*Enter a number (-1 to exit):  *");
    printf("\n* 1 - Add new student          *");
    printf("\n* 2 - Delete a student         *");
    printf("\n* 3 - Update student           *");
    printf("\n* 4 - Print a student          *");
    printf("\n* 5 - Print all students       *");
    printf("\n********************************\n");
    printf("\nEnter: ");
}

int main (int argc, char **argv) {
    int a;

    printMenu();
    scanf("%d", &a);

    while(a != -1) {
        switch(a) {
            case 1:     
                printf("1\n");
                break;
            case 2:     
                printf("2\n");
                break;
            case 3:         
                printf("3\n");
                break;
            case 4:         
                printf("4\n");
                break;
            case 5:         
                printf("5\n");
                break;
            default:       
                printf("\nInvalid answer!\n");
                break;
        }

        puts("");
        printMenu();
        scanf("%d", &a);  
    }
    return 0;
} 

```

I would like to check the input of `scanf`. For example if user enters a number it works successfully, but if user enter something like a string or a char it print non-stop the menu again and again.

I would like to check if user enters a number or not. If not I would like to ask again about input.
I have tried things like:

```
if(scanf("%d", &a)!=1) {
     printf("Enter again: ");
     scanf("%d", &a);
}

```

Or:

```
assert(scanf("%d", &a);

```

With `assert` function program stops executing but I want it to continue after while.
Any ideas?