Subject: fgetc and getchar, how do I stop echo.
To: 'netbsd-help' <netbsd-help@NetBSD.ORG>
From: John Maier <johnam@datastorm.com>
List: netbsd-help
Date: 07/12/1996 12:43:56
I have a question about fgetc and getchar.

I want to be able to create a menu so the user needs only to press a letter
to activate a function.

The functions fgetc and getchar are suppose to perform functions like this.
However I have found that a <CR> needs to entered before any more code is
allowed to execute.

I have tried setvbuf( stdin, NULL, _IONBF, 0 ) but fgetc still buffers
the input data.

Another problems is the echoing of characters to the screen.  For example,
I want all of the data entered by the user to be upper case, regardless
the state of the CapsLock key.  This would require me to:
1) handle each character as it comes in.
2) Echo the data to the console.

Simple program to show what I basically want to do:
#include<stdio.h>
#include<string.h>

void main(void)
{
	char szTempStr[2] = " \0";
	char szUpperCase[80];

	setvbuf( stdin, NULL, _IONBF, 0 ); /* no buffering */

	while(*szTempStr != '\n') /* loop until the EOL character is found */
	{
		*szTempStr = fgetc(stdin);	/* get character from input stream */
		
		if(*szTempStr > 0x5a)		/* if the character is higher than 0x5a (Z) */
			*szTempStr = *szTempStr - 0x20; /* make character upper case */

		strcat(szUpperCase, szTempStr); /* build the string following the command */
		printf("%c", *szTempStr);		/* print single upper case character */
		
	}
}

The only problem is, it doesn't work right, or should I say, as I expect it to.

Any help or ideas would be appreciated.

jam