S
sk
Hi everyone, I'm kind of new to C programming, so I thought that a
newsgroup would be the best place to ask a question about this.
I'm trying to write a small program that displays a menu and has the
user input a value(int). I'm only using getchar and printf to make
things simple.
I have the menu printing part down pretty well, but I'm getting an error
where the entire menu will print n+1 number of times when you input a
value with n-digits. I asked around a little, and some others said that
it was because getchar is buffered, and will just print for every char
that is passed. I'm stuck on how to make it so that the menu will only
print once, then ask the use for input.
This is how it is set up right now:
prints menu
getchar
while (getchar variable is not EOF)
{
prints menu
(conditionals for menu...)
getchar
}
Can anyone give me any ideas on how to fix this? Sorry if this is a
stupid question. Thanks in advance!
newsgroup would be the best place to ask a question about this.
I'm trying to write a small program that displays a menu and has the
user input a value(int). I'm only using getchar and printf to make
things simple.
I have the menu printing part down pretty well, but I'm getting an error
where the entire menu will print n+1 number of times when you input a
value with n-digits. I asked around a little, and some others said that
it was because getchar is buffered, and will just print for every char
that is passed. I'm stuck on how to make it so that the menu will only
print once, then ask the use for input.
This is how it is set up right now:
prints menu
getchar
while (getchar variable is not EOF)
{
prints menu
(conditionals for menu...)
getchar
}
Can anyone give me any ideas on how to fix this? Sorry if this is a
stupid question. Thanks in advance!