Message-Id: <199810010003.UAA21645@delorie.com> Comments: Authenticated sender is From: "George Foot" To: allen DOT asjp AT cableol DOT co DOT uk Date: Thu, 1 Oct 1998 01:01:14 +0000 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: Strange DJGPP bug Reply-to: mert0407 AT sable DOT ox DOT ac DOT uk CC: djgpp AT delorie DOT com X-mailer: Pegasus Mail for Win32 (v2.42a) On 30 Sep 98 at 18:40, Peter Allen wrote: > Test User wrote: > > > > On Sun, 27 Sep 1998, Peter Allen wrote: > > > > >Test User wrote: > > > > >> Here's a short C program: > > > > >> #include > > >> > > >> int main() > > >> { > > >> char buffer[256]; > > >> > > >> printf("Input: "); > > >> fgets(buffer, 255, stdin); > > >> printf("\nYou typed %s\n"); > > >> } > > > > >> When compiled with the Linux version of GCC, this program > > >> prints an Input: prompt. When the user types something and > > >> presses ENTER, it then prints the string the user typed, > > >> in the form of "\nYou typed %s\n", where \n is a newline and > > >> %s is the string the user typed, including the trailing newline. > > >> > > >> When compiled with DJGPP, the program just sits there until > > >> the user types something and presses ENTER. Then, the > > >> program spews out the Input: prompt and the string the > > >> user typed at the same time. For some reason, it executes > > >> fgets() first, and then executes both printf's together. You > > >> can't get it to print the prompt first, then call fgets(), > > >> and then print the results. You can substitute fgets() for > > >> your own elaborate loop system. You'll get the same result. > > > > >To save time switching between protected mode and dos, djgpp is > > >buffered, so the easiest way to make it print something on the > > >screen is to add \n to the end of printf ("input:") line. > > > > > Peter Allen > > > > That would look pretty strange. Imagine an FTP program that does > > this. The prompt would be on one line, and the command on a different > > line. How did they get BASH to work? It doesn't print "bash-2.01$ " > > and then have the user type the commands on the next line. Both > > the prompt and the user's input are on the same line. > > Woops, sorry. I forgot to say you could put fflush(stdout); at the end > instead. Sorry The buffer should be automatically flushed when you take input from stdin, so the code snippet above should work -- the text should be printed before the input is taken. It works fine on my machine, anyway. -- george DOT foot AT merton DOT oxford DOT ac DOT uk