Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sourceware DOT cygnus DOT com Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com Message-ID: <387C7BC9.355F3B7D@cadlab.tu-berlin.de> Date: Wed, 12 Jan 2000 14:04:10 +0100 From: Georg Fusz Organization: Techn.University Berlin X-Mailer: Mozilla 4.7 [en] (WinNT; I) X-Accept-Language: en MIME-Version: 1.0 To: Dtcohen AT aol DOT com CC: cygwin AT sourceware DOT cygnus DOT com Subject: Re: getc() problem with Cygwin v1.0 References: <95 DOT 95f94d16 DOT 25ab9bca AT aol DOT com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hallo Jim, at first in ANSI-C there is no function getc( void ). There is int getc( FILE *stream ) and int getchar( void ). The problem is a little bit more complicated. getchar() is reading one character from the input-stream and the function is not waiting for "RETURN". The question is: When is a keystroke put in in the stream "stdin"? The following little program shows this: #include #include int main( void ) { char buffer[81]; int i, ch; int re = 0; /*----------------------------------------*/ printf( "Enter a line: " ); /* Read in single line from "stdin": */ for( i = 0; (i < 80) && ((ch = getc( stdin )) != EOF) && (ch != '\n'); i++ ) { printf( "!ch = %c\n", ch ); buffer[i] = (char)ch; } /* Terminate string with null character: */ buffer[i] = '\0'; printf( "%s\n", buffer ); printf( "READY, press Enter\n" ); getchar(); return re; } /*--------------------*/ On my systems [ 1. Cygwin 20.1, 2. WindowsNT + MinGw] the loop starts when the "Return" is pressed and prints then one character at one time. If you need to wait until "RETURN" is pressed maybe you have succes with "gets()". Using "scanf()" is dangerous, because sometimes "RETURN" is left in the buffer. Dtcohen AT aol DOT com wrote: > > For Cygwin v1.0, getc() returns after every key is typed, instead > of waiting for the carriage return. This is incorrect behavior. > With Cygwin B20.1 it correctly waits for the carriage return. > > Does anyone know how this can be fixed? Any pointers to the > source of the problem are also appreciated. > > Many thanks, > Jim Grishaw > dtcohen AT aol DOT com -- Georg Fusz home-page: http://cadence.fb12.tu-berlin.de/~fusz/ Fon: Universitaet: +49 30 314 26 884 privat: : +49 30 815 30 32 Handy: : +49 173 20 10 696 -- Want to unsubscribe from this list? Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com