This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

B20: fgets() doesn't wait for input on stdin


For some reason, fgets() just skips over. Here's the code snippet:

int check_exists(char *thefile) {
	int aexists;
	char answer[5];

	aexists = open(thefile, O_RDONLY);
	if (aexists < 0) {
		close(aexists);
		return(0);
	} else {
		close(aexists);
		fprintf(stderr, "Warning. You are about to overwrite %s. Still do it?
(y/n) ", thefile);
		fgets(answer, sizeof(answer), stdin);
		answer[strlen(answer)-1] = '\0';
		if (answer[0] == 'y') {
			return(0);
		} else {
			printf("You typed %s\n", answer);
			exit(8);
		}
	}
}

This always results in "You typed" being printed. No input it waited on.
This is B20.0 running under Win98. (This code has been tested and works
under FreeBSD).

Paul
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]