Mail Archives: djgpp/1996/11/27/04:59:19
Mr David Potts wrote:
> #include<stdio.h>
> #include<conio.h>
> int main(void)
> {
> printf("Before getch");
> getch();
> return(0);
>
> }
> But when I ran it, it waited for a key press *then* printed
> the text rather than the other way round. What is going on?
The cause is file buffering. As printf(...) is somewhat like
fprintf(stdout,...), output is buffered and you need fflush(stdout)
after printf to force text to appear. Buffer is automaticaly flushed
after printing '\n' and before program exits. So use either
printf("Before getch\n"); or printf("Before getch"); fflush(stdout);
--
Sincerely yours, Ilya
-----------------------------------------------------------------------------
mailto://ilya AT spy DOT isp DOT nsc DOT ru
http://spy.isp.nsc.ru
- Raw text -