Question: ```
#include <stdio.h>
#include <stdlib.h>

main()
{
    int Q = 1;
    while(Q==1)
    { 
        system("clear");
        printf("MAIN MENU\n");
        printf("--------------------------------------\n");
        printf("1 - See all files\n");
        printf("2 - See all files with permission\n");
        printf("3 - VIM Editor\n");
        printf("4 - EXIT\n");

        fputs("Enter Choice : ",stdout);
        char ch = getchar();

        switch(ch)
        {
            case '1' : system("ls"); break;
            case '2' : system("ls -l"); break;
            case '3' : system("vi"); break;
            case '4' : Q=0; break;
            default  : puts("Wrong Choice.."); break;
        }

        fflush(stdin);

        fputs("PRESS ENTER TO CONTINUE...",stdout);
        getchar();
    }
}

```

The getchar() does not pause rather it just clears the screen and starts the menu again.

What is the cause of such problems?
I am using tutorialspoint codingground online compiler.

Answer: 
You could identify the problem yourself if you displayed what the unexpected character is:

```
default:   printf ("Unrecognized choice:  '%c' (%d)", ch, ch);  break;

```

That is not a bad technique to use in any similar situation. If the code somehow gets unexpected input, say so and show what is known.
This happens because fflush() doesn't always flush the stdin and it's not the safest method to clear the buffer. Try using scanf(" %c", &yourcharvariable) instead or else you should use another getchar() to consume the '\n' left by your first input.

Try this code instead:

```
#include <stdio.h>
#include <stdlib.h>

main()
{
    int Q = 1;
    while(Q==1)
    { 
        system("clear");
        printf("MAIN MENU\n");
        printf("--------------------------------------\n");
        printf("1 - See all files\n");
        printf("2 - See all files with permission\n");
        printf("3 - VIM Editor\n");
        printf("4 - EXIT\n");

        fputs("Enter Choice : ",stdout);
        char ch = getchar();

        switch(ch)
        {
            case '1' : system("ls"); break;
            case '2' : system("ls -l"); break;
            case '3' : system("vi"); break;
            case '4' : Q=0; break;
            default  : puts("Wrong Choice.."); break;
        }

        fflush(stdin); // This doesn't always work. 
        getchar(); // It consumes the '\n' left by your first getchar().
        fputs("PRESS ENTER TO CONTINUE...",stdout);
        getchar();
    }
}

```