Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 23rd, 2007, 1:16 AM   #1
lucifer
Programmer
 
lucifer's Avatar
 
Join Date: Oct 2005
Posts: 84
Rep Power: 3 lucifer is on a distinguished road
How to clear console buffers

Hi
i have to take input from user in console using Console.Read() and Console.Readline() functions but whenever i use Console.Readline() before Console.Read() , the Console.Read() funtion does not execute
plz help
eg

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            int x=Console.Read();
            string str = Console.ReadLine();
          int z=  Console.Read();
        }
    }
}
__________________
"You're good... but me, I'm magic"
lucifer is offline   Reply With Quote
Old Mar 23rd, 2007, 5:22 AM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
First of all, Console.Read is used for reading single characters, not tokens. Read the int in using int x = int.Parse(Console.ReadLine()); .

The reason the second Read didn't seem to be executing was that you were entering one on each line: when you typed an integer, the first function read the character... then the next read the rest of the line. The string you typed was read partially by the third, and then dropped when your program finished.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 24th, 2007, 4:56 AM   #3
lucifer
Programmer
 
lucifer's Avatar
 
Join Date: Oct 2005
Posts: 84
Rep Power: 3 lucifer is on a distinguished road
Quote:
Originally Posted by Ooble View Post
First of all, Console.Read is used for reading single characters, not tokens. Read the int in using int x = int.Parse(Console.ReadLine()); .

The reason the second Read didn't seem to be executing was that you were entering one on each line: when you typed an integer, the first function read the character... then the next read the rest of the line. The string you typed was read partially by the third, and then dropped when your program finished.
even if i enter single characters still the problem persists
i have also tried to do this
char x=(char)Console.Read();
            string str = Console.ReadLine();
            char z = (char)Console.Read();
__________________
"You're good... but me, I'm magic"
lucifer is offline   Reply With Quote
Old Mar 25th, 2007, 1:55 PM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Try typing:
x Something
m
Bet it'll work.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Making a C app run without a console ibbrowne3 C 7 Nov 21st, 2006 12:40 PM
Manipulating the console using Windows API rup C++ 2 Nov 17th, 2006 1:04 PM
Simple question, I think? Phonetic Bash / Shell Scripting 3 Nov 15th, 2006 3:31 AM
The Black Art of Video Game Console Design lostcauz Book Reviews 0 Apr 26th, 2006 7:31 PM
Clear screen with Java Eric the Red Java 9 Feb 22nd, 2006 10:28 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:57 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC