From: gfoot AT mc31 DOT merton DOT ox DOT ac DOT uk (George Foot) Newsgroups: comp.os.msdos.djgpp Subject: Re: Strange behaviour... Date: 9 Mar 1997 01:46:17 GMT Organization: Oxford University Lines: 33 Message-ID: <5ft4p9$db2@news.ox.ac.uk> References: <33219722 DOT 5A96 AT mbox DOT vol DOT it> NNTP-Posting-Host: mc31.merton.ox.ac.uk To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Stefano Bizzi (sbcinf AT mbox DOT vol DOT it) wrote: : I have a little problem compiling a simple program... : With a code like this: : .... : printf("\nHello World"); : printf("\nSomething else..."); : clrscr(); : ..... : The compiler execute the clrscr() function BEFORE the last printf(). : Then, it writes "Hello World", it clear the screen and, then, write : "Something else". Why? (I compiled the from RHide). You are mixing commands from stdio.h and conio.h, which is generally not a good idea. printf() sends to stdout, which is line buffered. This means that nothing gets printed until you send a \n character. If you stick to stdio.h routines, this isn't a problem because, for instance, scanf() will clear the buffer before waiting for input. However, you are using clrscr() which is a conio.h function, and so the buffer is not flushed. You have two main options here: 1) Put fflush(stdout) before clrscr() to manually flush the buffer 2) Only use conio.h routines (i.e. use cprintf() instead of printf()) HTH -- George Foot Merton College, Oxford.