|
-
Feb 22nd, 2006, 09:00 AM
#1
Thread Starter
Hyperactive Member
Console.Read() - Please help C# newbie
Hi,
I want to create menu driven condole application
(1. Do this, 2. Do that, 3. Exit)
I have a stranger problem with Console.Read()
I'm reading a character in a loop using Console.Read()
and displaying it using Console.Write()
VB Code:
public static void Test()
{
int i;
char c;
while (true)
{
i = Console.Read ();
c = (char) i;
Console.WriteLine ("Echo: {0}", c);
}
}
When I press 5<Enter>, then 9<Enter> I should be getting this:
Instead, I'm getting this:
VB Code:
5
Echo: 5
Echo: // remembers char 13 - line feed
Echo: // remembers char 10 - new line
9
Echo: 9
Echo: // remembers char 13 - line feed
Echo: // remembers char 10 - new line
After stepping through the code I realized that
the Console.Read() remembers the enter key as well (char 13 and 10)
that's why the two empty echos after the actual number.
How can I solve this? Flash the buffer?
I need to use Console.Read() for reading single digits.
Any help appreciated.
-
Feb 22nd, 2006, 09:55 AM
#2
Re: Console.Read() - Please help C# newbie
-
Feb 22nd, 2006, 11:12 AM
#3
Thread Starter
Hyperactive Member
Re: Console.Read() - Please help C# newbie
Yeah,
I wanted to do this with the .Read() but I give up (spend too much time on it although I learned few things doing so).
I did my menu using ReadLine() instead and it works well.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|