D - stream.d bug [scanf() & getc()]
- Andrew Edwards (34/34) Jul 12 2003 Maybe the bug's just in my head; however, the following code produces
- Helmut Leitner (5/8) Jul 12 2003 I think it would be helpful if you would make clear what you desired.
- Andrew Edwards (10/11) Jul 12 2003 Sorry!
- Sean L. Palmer (7/20) Jul 12 2003 It would probably be enlightening for you if you print out the ascii cod...
- Andrew Edwards (8/10) Jul 12 2003 IC...
- Vathix (8/19) Jul 12 2003 I think, like in C, you have to take the newline out of the stream first...
- Andrew Edwards (7/11) Jul 12 2003 could
Maybe the bug's just in my head; however, the following code produces undesired results! Regards, Andrew ------------code----------- import stream; void main() { char something; // with scanf() stdout.printf("Type a character: "); stdin.scanf("%c",&something); stdout.printf("You typed: %c\n", something); stdout.printf("Now type something else: \n"); stdin.scanf("%c",&something); stdout.printf("You typed: %c\n\n", something); // with getc() stdout.printf("Type a character: "); something = stdin.getc(); stdout.printf("You typed: %c\n", something); stdout.printf("Now type something else: \n"); something = stdin.getc(); stdout.printf("You Typed: %c", something); } ------------output----------- C:\d>scan Type a character: 2 You typed: 2 Now type something else: You typed: Type a character: You typed: Now type something else: + You Typed: +
Jul 12 2003
Andrew Edwards wrote:Maybe the bug's just in my head; however, the following code produces undesired results!I think it would be helpful if you would make clear what you desired. -- Helmut Leitner leitner hls.via.at Graz, Austria www.hls-software.com
Jul 12 2003
"Helmut Leitner" <helmut.leitner chello.at> wrote...I think it would be helpful if you would make clear what you desired.Sorry! I'm simply attempting to get two characters from the user with successive calls to either scanf() or getc(). When first prompted, if the user inputs multiple characters into the stream, the scanf() or getc() will read from the remaining characters. However, if the user only inputs one character and then press enter, both scanf() and getc() ignores the next two calls. Only on the third call will the user get a chance to input additional information. Andrew
Jul 12 2003
It would probably be enlightening for you if you print out the ascii code of each character received instead of the characters themselves. Sean "Andrew Edwards" <edwardsac spamfreeusa.com> wrote in message news:bep22g$18j8$1 digitaldaemon.com..."Helmut Leitner" <helmut.leitner chello.at> wrote...andI think it would be helpful if you would make clear what you desired.Sorry! I'm simply attempting to get two characters from the user with successive calls to either scanf() or getc(). When first prompted, if the user inputs multiple characters into the stream, the scanf() or getc() will read from the remaining characters. However, if the user only inputs one characterthen press enter, both scanf() and getc() ignores the next two calls.Onlyon the third call will the user get a chance to input additional information. Andrew
Jul 12 2003
"Sean L. Palmer" <palmer.sean verizon.net> wrote...It would probably be enlightening for you if you print out the ascii codeofeach character received instead of the characters themselves.IC... The question then, should be: How do I flush the buffer after extracting the first character? The closest thing I can find is fflush(), which does not work on stdin. Thanks, Andrew
Jul 12 2003
I think, like in C, you have to take the newline out of the stream first or it'll be the next input. So, perhaps you want to loop getc until it's \n, printing out only the first one. In C it could return EOF, but in D it could throw a ReadError. "Andrew Edwards" <edwardsac spamfreeusa.com> wrote in message news:bep99c$1fig$1 digitaldaemon.com..."Sean L. Palmer" <palmer.sean verizon.net> wrote...codeIt would probably be enlightening for you if you print out the asciioftheeach character received instead of the characters themselves.IC... The question then, should be: How do I flush the buffer after extractingfirst character? The closest thing I can find is fflush(), which does not work on stdin. Thanks, Andrew
Jul 12 2003
"Vathix" <vathix dprogramming.com> wrote...I think, like in C, you have to take the newline out of the stream firstorit'll be the next input. So, perhaps you want to loop getc until it's \n, printing out only the first one. In C it could return EOF, but in D itcouldthrow a ReadError.IC... I'll try it out sometime tomorrow evening after I finish my homework! Thanks, Andrew
Jul 12 2003