473,569 Members | 2,526 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Clear Buffer before my Second Console.Read()

Okay I call Console.Read() twice. However when I come up on my second
Console.Read() ASCII character 10 is already on the console (that's a line
feed).

How do I clear out that line feed before I call Console.Read() again?
Nov 16 '05 #1
3 12394
Steve,

Can you show the code where this is happening? Console.Read shouldn't
be feeding you the line character (I think).

If anything, why not use ReadLine?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"- Steve -" <se****@foundat ion.sdsu.edu> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Okay I call Console.Read() twice. However when I come up on my second
Console.Read() ASCII character 10 is already on the console (that's a line
feed).

How do I clear out that line feed before I call Console.Read() again?

Nov 16 '05 #2
char letter = (char)Console.R ead();

The first time through it is fine. The second time I can see in the
debbuger the a line feed is already in there.

I'm using Read instead of ReadLine becuase I just want a single char instead
of a string, and it seems like it would be simplier to do it this way.

Of course depending on what it takes to get around this issue I might change
my ind.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:uu******** ******@TK2MSFTN GP15.phx.gbl...
Steve,

Can you show the code where this is happening? Console.Read shouldn't
be feeding you the line character (I think).

If anything, why not use ReadLine?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"- Steve -" <se****@foundat ion.sdsu.edu> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Okay I call Console.Read() twice. However when I come up on my second
Console.Read() ASCII character 10 is already on the console (that's a
line feed).

How do I clear out that line feed before I call Console.Read() again?


Nov 16 '05 #3
Steve,

You probably should do a readline. The reason for this is that when
dealing with console input, the buffer is not going to be filled until a
line is entered. Because of this, it's easier to just read the line and
process the string than it is to read character by character.

In .NET 2.0 however, there are ways of detecting when there is a
keypress, which might be of use to you.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"- Steve -" <se****@foundat ion.sdsu.edu> wrote in message
news:u$******** ******@TK2MSFTN GP14.phx.gbl...
char letter = (char)Console.R ead();

The first time through it is fine. The second time I can see in the
debbuger the a line feed is already in there.

I'm using Read instead of ReadLine becuase I just want a single char
instead of a string, and it seems like it would be simplier to do it this
way.

Of course depending on what it takes to get around this issue I might
change my ind.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote
in message news:uu******** ******@TK2MSFTN GP15.phx.gbl...
Steve,

Can you show the code where this is happening? Console.Read shouldn't
be feeding you the line character (I think).

If anything, why not use ReadLine?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"- Steve -" <se****@foundat ion.sdsu.edu> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Okay I call Console.Read() twice. However when I come up on my second
Console.Read() ASCII character 10 is already on the console (that's a
line feed).

How do I clear out that line feed before I call Console.Read() again?



Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
105777
by: Dave | last post by:
Hi, I have done some research, trying to Clear The Screen in java code. The first option was the obv: system.out.print("\n\n\n\n\n\n\n\n\n\n\n\n"); then i heard about this method: System.out.print((char)27 + "[2J");
3
5360
by: voidstar | last post by:
Hi, I have the following problem: I use "getch" to monitor keypresses and the I use "cin" to input a string. When I type in 'y', the 'y' character appears, so I need to hit backspace before typing the string. c = getch(); cin >> str;
5
21046
by: nx-2000 | last post by:
I've got a very large C# forms app and now that its being used in bigger environments we're getting a steady stream of "why does it do this?" problems. The most nagging of which right now is that when a MessageBox.Show() is displayed, if the user hits enter or esc, those keys get passed back to the form. From searching online, this is...
1
6203
by: AD | last post by:
Hi I am trying to read elements of a vector from console (cin) in two steps ie, read a list of numbers from cin. Sort these. Then read from cin again and append in same vector. /*****************************************************************/ #include<iostream> #include<algorithm> #include<vector>
1
2907
by: noel.phillips | last post by:
Hi, I have two threads in my application, one that decodes audio to a stream and one that encodes a stream to a file. If I run them as two seperate processes I can pipe the output from one to the input of the other - and all is well. The writes to standard output are obviously synchronous, so the decoding occurs at the rate at which the...
2
13649
Osoascam
by: Osoascam | last post by:
Hi! I made this code in order to "create" a buffer... It works perfectly when reading from console, but it just doesn't work for redinf from files. (Read after the function for the code explanation) NAME is a class variable, char* void buffer(FILE* entrada, char separador) //entrada is input (sdtin for consol) { int numChars = 2; ...
331
14737
by: Xah Lee | last post by:
http://xahlee.org/emacs/modernization.html ] The Modernization of Emacs ---------------------------------------- THE PROBLEM Emacs is a great editor. It is perhaps the most powerful and most versatile text editor. And, besides text editing, it also serves as a
7
10164
by: Just Me | last post by:
I am writing a small windows applicationa and I am writing console.writeline data to the console window. But i wanted to clear the area before writing to the window. I found the console.clear method, but when I run it it fails with an uinhandled exception and the exception is that it does not have the handle to the window. IM assuming, I...
9
19146
by: pbd22 | last post by:
Hi. Does anybody know how to issue a clear screen command like DOS "cls" in a telnet session? Thanks!
0
7614
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8125
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7974
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.