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?
To solve your issue, try this: