473,795 Members | 3,279 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 12412
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
105843
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
5384
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
21124
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 apparently by design(for whom, I don't know, why its not optional, I _really_ don't know). This...
1
6226
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
2917
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 encoder can process...
2
13658
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; //# of characters read char* aux; buff =...
331
14988
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
10335
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 need to determine the console windo handle, but Im not sure, has anyone used this, can point me in...
9
19182
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
10435
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10213
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10163
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9037
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6779
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.