digitalmars.D.learn - flush input buffer?
- Michael P. (7/7) Oct 18 2008 Okay, so I'm sure if flushing the input buffer is what I want, or if tha...
- Nick Sabalausky (12/26) Oct 18 2008 I'm not sure what lib or function you're using to read the input, but th...
- Michael P. (2/33) Oct 18 2008 Oh yeah, forgot to say that I am using din.readf() for input.
- Nick Sabalausky (14/55) Oct 18 2008 Ok, I took a look at the phobos documentation for that. Looks like this
- Michael P. (3/65) Oct 18 2008 No, unfortunately that didn't work.
Okay, so I'm sure if flushing the input buffer is what I want, or if that even makes sense, so I'll say what I'm trying to do first to see if that's what I want. So, I made this program where you specify the number of digits in a number you want to remember. Then, it ask you how many questions. Anyways, a number will show up. Then, you have 4 seconds to remember. Then, 30 lines are skipped as my "clearing of the screen". Sleep another second. You are then asked to type in the number you saw. The problem I have is that the user can just type in the number while they see it, and what the typed will show up when the prompt comes up. What I want to do is "flush the input buffer" just before I request for input so the user can no longer type in the number while they see it. -Michael P.
Oct 18 2008
"Michael P." <baseball.mjp gmail.com> wrote in message news:gdd02h$1uui$1 digitalmars.com...Okay, so I'm sure if flushing the input buffer is what I want, or if that even makes sense, so I'll say what I'm trying to do first to see if that's what I want. So, I made this program where you specify the number of digits in a number you want to remember. Then, it ask you how many questions. Anyways, a number will show up. Then, you have 4 seconds to remember. Then, 30 lines are skipped as my "clearing of the screen". Sleep another second. You are then asked to type in the number you saw. The problem I have is that the user can just type in the number while they see it, and what the typed will show up when the prompt comes up. What I want to do is "flush the input buffer" just before I request for input so the user can no longer type in the number while they see it. -Michael P.I'm not sure what lib or function you're using to read the input, but there should be some way to do an asynchronous read from the input buffer to read input *only* if input already exists and just sinply return nothing instead of waiting if no input exists. Then you could do something like this: do { inputDataToThrowAway = AsyncRead(); } while(data was actualy read); output("Please enter your answer"); waitForInputAndReadIt();
Oct 18 2008
Nick Sabalausky Wrote:"Michael P." <baseball.mjp gmail.com> wrote in message news:gdd02h$1uui$1 digitalmars.com...Oh yeah, forgot to say that I am using din.readf() for input.Okay, so I'm sure if flushing the input buffer is what I want, or if that even makes sense, so I'll say what I'm trying to do first to see if that's what I want. So, I made this program where you specify the number of digits in a number you want to remember. Then, it ask you how many questions. Anyways, a number will show up. Then, you have 4 seconds to remember. Then, 30 lines are skipped as my "clearing of the screen". Sleep another second. You are then asked to type in the number you saw. The problem I have is that the user can just type in the number while they see it, and what the typed will show up when the prompt comes up. What I want to do is "flush the input buffer" just before I request for input so the user can no longer type in the number while they see it. -Michael P.I'm not sure what lib or function you're using to read the input, but there should be some way to do an asynchronous read from the input buffer to read input *only* if input already exists and just sinply return nothing instead of waiting if no input exists. Then you could do something like this: do { inputDataToThrowAway = AsyncRead(); } while(data was actualy read); output("Please enter your answer"); waitForInputAndReadIt();
Oct 18 2008
"Michael P." <baseball.mjp gmail.com> wrote in message news:gddeog$26je$1 digitalmars.com...Nick Sabalausky Wrote:Ok, I took a look at the phobos documentation for that. Looks like this should work (I use Tango instead of phobos, so I haven't tested it. Hopefully it'll work): void clearInputBuffer() { while(din.available() > 0) { din.getc(); } } Calling that function before you read the user's input *should* do what you're looking for."Michael P." <baseball.mjp gmail.com> wrote in message news:gdd02h$1uui$1 digitalmars.com...Oh yeah, forgot to say that I am using din.readf() for input.Okay, so I'm sure if flushing the input buffer is what I want, or if that even makes sense, so I'll say what I'm trying to do first to see if that's what I want. So, I made this program where you specify the number of digits in a number you want to remember. Then, it ask you how many questions. Anyways, a number will show up. Then, you have 4 seconds to remember. Then, 30 lines are skipped as my "clearing of the screen". Sleep another second. You are then asked to type in the number you saw. The problem I have is that the user can just type in the number while they see it, and what the typed will show up when the prompt comes up. What I want to do is "flush the input buffer" just before I request for input so the user can no longer type in the number while they see it. -Michael P.I'm not sure what lib or function you're using to read the input, but there should be some way to do an asynchronous read from the input buffer to read input *only* if input already exists and just sinply return nothing instead of waiting if no input exists. Then you could do something like this: do { inputDataToThrowAway = AsyncRead(); } while(data was actualy read); output("Please enter your answer"); waitForInputAndReadIt();
Oct 18 2008
Nick Sabalausky Wrote:"Michael P." <baseball.mjp gmail.com> wrote in message news:gddeog$26je$1 digitalmars.com...No, unfortunately that didn't work. I tried calling din.flush() before the input too and it didn't work either.Nick Sabalausky Wrote:Ok, I took a look at the phobos documentation for that. Looks like this should work (I use Tango instead of phobos, so I haven't tested it. Hopefully it'll work): void clearInputBuffer() { while(din.available() > 0) { din.getc(); } } Calling that function before you read the user's input *should* do what you're looking for."Michael P." <baseball.mjp gmail.com> wrote in message news:gdd02h$1uui$1 digitalmars.com...Oh yeah, forgot to say that I am using din.readf() for input.Okay, so I'm sure if flushing the input buffer is what I want, or if that even makes sense, so I'll say what I'm trying to do first to see if that's what I want. So, I made this program where you specify the number of digits in a number you want to remember. Then, it ask you how many questions. Anyways, a number will show up. Then, you have 4 seconds to remember. Then, 30 lines are skipped as my "clearing of the screen". Sleep another second. You are then asked to type in the number you saw. The problem I have is that the user can just type in the number while they see it, and what the typed will show up when the prompt comes up. What I want to do is "flush the input buffer" just before I request for input so the user can no longer type in the number while they see it. -Michael P.I'm not sure what lib or function you're using to read the input, but there should be some way to do an asynchronous read from the input buffer to read input *only* if input already exists and just sinply return nothing instead of waiting if no input exists. Then you could do something like this: do { inputDataToThrowAway = AsyncRead(); } while(data was actualy read); output("Please enter your answer"); waitForInputAndReadIt();
Oct 18 2008