Re: Reading from console



vid512@xxxxxxxxx wrote:
Hi, i am designing routines to read from console. Such as "read signed
decimal number", "read string up to 10 chars", etc.

Maybe you have noticed, that standard way to work with this kind of
input, is to let user type entire line first, and then process it.

I will not go into detail, but in my idea how to implement this,
reading from console will ALWAYS beheave like this. Even if you are
going to read one character. so there will be nothing like C's getc(),
which really only takes one char.

Do you think this would be a problem?

In fact, getc() is only exception to rule that came in my mind

stdin is buffered. getc() will not read a char until you hit return; it does not return as soon as a char is typed. To prove this to yourself, run this (untested) program, type a letter, type a backspace, type a different letter, and hit return.

#include <stdio.h>

int main(void)
{
int ch;

ch = getc(stdin);
printf("received %c\n", ch);

return 0;
}

Note first that there will be no output until you hit return. Note second that the second letter will be printed.

On some systems, probably all, it is possible to turn buffering off in a system-specific way, though.

--
Thomas M. Sommers -- tms@xxxxxx -- AB2SB

.



Relevant Pages

  • Re: 250K win
    ... One thing I learned this far is that with Dwarf Priest you want *BLESS* as one of the first prayers to learn. ... My last char just got wonderful start with +3 lxbow and killed Grip as his first kill: from clvl 1 directly to clvl 4. ... Second monster was novice warrior waiting behind a door which in turn killed my char (didn't get hit in for four turns. ...
    (rec.games.roguelike.angband)
  • Re: 250K win
    ... started playing for turns you'd hit 600k pretty easily... ... Bless and detect doors/stairs. ... My last char just got wonderful start with +3 lxbow and killed Grip as ... from clvl 1 directly to clvl 4. ...
    (rec.games.roguelike.angband)
  • Re: Bored with WOW
    ... > mistake, yes there will be certain lull levels, but power on and wait til u ... > factor...abandoning a char just seems such a shame ... hmm, to be honest, I didn't see much difference when my mage hit 60. ... I suppose after getting my epic mount, ...
    (alt.games.warcraft)
  • Re: IE7 Beta 3 issue
    ... Outlook 2003 with preview screen on. ... Hit the print button and error ... Internet Explorer Scrit Error ... Char 1 ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Speed question and such.... - 1.Daddy (0/1)
    ... Now what benefits are given to the char ... blows/turn, I hit, hit, the enemy misses more often, I hit I hit, etc. ... what about those reports of Al Qaeda members using ...
    (rec.games.roguelike.angband)