Re: Reading from console
- From: "T.M. Sommers" <tms@xxxxxx>
- Date: Mon, 30 Oct 2006 13:22:45 -0500
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
.
- Follow-Ups:
- Re: Reading from console
- From: vid512@xxxxxxxxx
- Re: Reading from console
- References:
- Reading from console
- From: vid512@xxxxxxxxx
- Reading from console
- Prev by Date: Re: A modern view of the halting problem
- Next by Date: Re: Min/max function (saturation)
- Previous by thread: Reading from console
- Next by thread: Re: Reading from console
- Index(es):
Relevant Pages
|