No No.
Please, I've said it in my previous post, it returns
a single character; not a string. There is no such character as 'p\n', it is incorrect. It will return plain '\n' if it reads one...
Suppose you use other input functions such as scanf. Let's say you call
scanf("%d");
.
Now, lets assume you type 26 and press enter. You will also without knowing enter a '\n' in the input buffer; scanf reads the 26 and ignores the '\n'.
It is safe if you call scanf again as it tends to ignore it.
But, if you call getchar, it will most likely read that '\n' and you won't get a chance to enter anything.
You should use fflush(stdin) to flush out all the garbage characters, if any.
However, it may not be your problem. That is why I asked for you to post your full code.
And please read my first post.
unoriginal wrote: |
---|
Always do something like this to avoid case problems:char ch = tolower(getchar());
EDIT: Another thing, you could check if your getchar call is failing.
Like,
1 2 3 4 5 6 7
|
if((ch=getchar()) == EOF)
{
/* getchar() failed for some reason...
* print error message or debug
*/
perror("getchar failed.");
}
|
|
If none of what I suggested worked then please post the complete code you think is creating the problem. I and others can't help much with the little info you just posted.
-unoriginal (if my English seems bad, please forgive me.)