Mail Archives: djgpp/1996/10/09/09:36:10
Tony Sideris wrote:
>
> I'm trying to do this simple little C thing, but it won't work right...I
> copied it right out of a C book.
> Here's what I type:
> main()
> {
> char ch;
> printf("Type a character: ");
Just add
fflush(stdout);
> ch = getche();
> printf("\nYou typed: %c", ch);
> }
>
> After I compile it, I run it and the cursor just goes to next line
> (which is blank) and does nothing. Then, for example, I type p it says:
>
> pType a character:
> You typed: p
Welcome in the UNIXish world of buffered streams. stdout is
usually flushed when it encounters a \n (or when you printout
n characters not equal \n, where n is typically 16384)
The second line is only printed because the exit() function
flushes and closes (?) stdout.
Ciao
Tom
*************************************************************
* Thomas Demmer *
* Lehrstuhl fuer Stroemungsmechanik *
* Ruhr-Uni-Bochum *
* Universitaetsstr. 150 *
* D-44780 Bochum *
* Tel: +49 234 700 6434 *
* Fax: +49 234 709 4162 *
* Voice/Fax Box: +49 2561 91371 2056 *
* http://www.lstm.ruhr-uni-bochum.de/~demmer *
*************************************************************
- Raw text -