Question: I have the following piece of code where **check** is for char type

```
do{
      printf("Do you want to add an edge(n to stop adding)\n");
      check = getchar();
}while(check!='n');

```

and

```
do{
      printf("Do you want to add an edge(n to stop adding)\n");
      scanf("%c",&check);

}while(check!='n');

```

Both of them produce the same output

For example for the **r\n** I get **Do you want to add an edge** twice and for say **tt\n** I get the same question thrice followed by asking the input. 

My question is how to avoid it and why is it happening?

Answer: 
To solve your issue, try this:

```
void main()
{
    char check;
    char c;
    do
    {
        printf("Do you want to add an edge(n to stop adding)\n");
        check = getchar();
        do { c = getchar(); } while (c != '\n' && c != EOF);  // This gobbles the rest of the chars on stdin
    } while(check != 'n' && check != EOF);
}

```
I use nano compiler in ubbuntu for my coding of a program.

The program asks for a input and I need only single digit numbers as my input, and "normal program operations" immediately after that input should continue the program.

The program must continue to follow the next operation written down in the code like printf(" ").

Example

```
-----------start-------------

Input : 2 3 4 5 6 7

------------end-----------------

```

without having the user to input " " (space bar), I would like to incorporate the " " (space bar) in the program itself. The inputting is continued only if the user --

1. inputs manually the space bar button
2. hits the ENTER button

either of which I do not want.