digitalmars.D.learn - reading console in an 'endless' loop
- Alexander Panek (21/21) Jun 12 2005 Hello,
- Derek Parnell (23/48) Jun 12 2005 The code below works ...
- Alexander Panek (4/49) Jun 12 2005 thanks, works fine! :)
- Ben Hinkle (2/7) Jun 12 2005 note std.cstream publically imports both std.stream and std.c.stdio so t...
Hello, I`m programming a little shell in D with some scripting-possibilities. Reading a file is no problem, using std.stream.file. But I also have to read stdin to get some input from the user - that`s where my program 'crashes' in any way. First I`ve tried to do it like that: while(true) write(prompt); // writing something like "10:20:33$c:\>" scanf("%*.s", input); // input is char[] } In the very first step of the loop all works fine, but as soon as i hit enter/return it just prints prompt, without waiting for an acknowledge from stdin. I also tried it with getc(), getch(), getchar(), .. - always printing just my prompt-string after the first step. Is there anybody who already tried something like that? I don`t really see a problem there, it`s the same way as I`d do it in C (as far as we have only C-wrappers for stdin). Regards, Alex -- huh? did you say something? :o
Jun 12 2005
On Sun, 12 Jun 2005 11:28:15 +0200, Alexander Panek wrote:Hello, I`m programming a little shell in D with some scripting-possibilities. Reading a file is no problem, using std.stream.file. But I also have to read stdin to get some input from the user - that`s where my program 'crashes' in any way. First I`ve tried to do it like that: while(true) write(prompt); // writing something like "10:20:33$c:\>" scanf("%*.s", input); // input is char[] } In the very first step of the loop all works fine, but as soon as i hit enter/return it just prints prompt, without waiting for an acknowledge from stdin. I also tried it with getc(), getch(), getchar(), .. - always printing just my prompt-string after the first step. Is there anybody who already tried something like that? I don`t really see a problem there, it`s the same way as I`d do it in C (as far as we have only C-wrappers for stdin). Regards, AlexThe code below works ... <code> module test; import std.cstream; import std.stream; void main() { char[] prompt; char[] input; prompt = "Yeah?: "; while(input != "quit" && din.eof() == false) { dout.writef("%s", prompt); input = din.readLine(); } } </code> -- Derek Parnell Melbourne, Australia 12/06/2005 9:31:22 PM
Jun 12 2005
On Sun, 12 Jun 2005 13:32:49 +0200, Derek Parnell <derek psych.ward> wrote:On Sun, 12 Jun 2005 11:28:15 +0200, Alexander Panek wrote:thanks, works fine! :) -- huh? did you say something? :oHello, I`m programming a little shell in D with some scripting-possibilities. Reading a file is no problem, using std.stream.file. But I also have to read stdin to get some input from the user - that`s where my program 'crashes' in any way. First I`ve tried to do it like that: while(true) write(prompt); // writing something like "10:20:33$c:\>" scanf("%*.s", input); // input is char[] } In the very first step of the loop all works fine, but as soon as i hit enter/return it just prints prompt, without waiting for an acknowledge from stdin. I also tried it with getc(), getch(), getchar(), .. - always printing just my prompt-string after the first step. Is there anybody who already tried something like that? I don`t really see a problem there, it`s the same way as I`d do it in C (as far as we have only C-wrappers for stdin). Regards, AlexThe code below works ... <code> module test; import std.cstream; import std.stream; void main() { char[] prompt; char[] input; prompt = "Yeah?: "; while(input != "quit" && din.eof() == false) { dout.writef("%s", prompt); input = din.readLine(); } } </code>
Jun 12 2005
The code below works ... <code> module test; import std.cstream; import std.stream;note std.cstream publically imports both std.stream and std.c.stdio so the second import isn't needed.
Jun 12 2005