Problem in Getting Menu Option
I'm currently doing an assignment but I've desperately to make this work:
Code:
int addString(void){
char addAnother, str[100];
do{
printf("Enter string: ");
gets(str);
/* Some not important code here */
printf("Add another? [Press Y for Yes]");
addAnother = getchar(); /* Problem exist here */
}while( (toupper(addAnother)) == Y );
return 0;
}
Now, as I was asked to add another, I press 'y' then Enter and it will skip the gets() statement on top, like this:
Output:
------------------------------------
Add another? [Press Y for Yes]y
Enter string: Add another? [Press Y for Yes]
------------------------------------
I've tried to use getch() instead but end up the output like this:
------------------------------------
Add another? [Press Y for Yes]
Enter string: y
------------------------------------
which the y always appear after my 'Enter string' prompt (which I didn't want).
Is there any way that I can achieve this "menu selection" hassle?