Mail Archives: djgpp/1998/09/27/07:15:40
From: | user AT ts001d22 DOT cin-oh DOT concentric DOT net (Test User)
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Strange DJGPP bug
|
Date: | 27 Sep 1998 04:10:07 PDT
|
Organization: | Concentric Internet Services
|
Lines: | 29
|
Message-ID: | <slrn70rpos.5bh.user@ts001d22.cin-oh.concentric.net>
|
NNTP-Posting-Host: | ts001d22.cin-oh.concentric.net
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Here's a short C program:
#include <stdio.h>
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.
- Raw text -