First of all:
SCANF not language defined.
CHAR not defined by language.
Okay, with that out of the way ...
The scanf() function returns an integer. This integer is the number of input elements assigned or the value of the EOF macro if an input failure occurs before the first conversion.
You did not check the return value of the scanf() call, so you do not know what happened. Everything could work fine, or the input stream might finish before the first conversion, or (not for% c), the conversion might have failed.
Check the return value of scanf() . Indeed, it always checks the return value of all <stdio.h> Functions .
char ch; int result = scanf("%c", &ch); if (result == 1) ; else if (result == 0) ; else if (result == EOF) ;
When the result of calling scanf() is EOF , if you want more information about the cause of the input failure, you can use feof() and / or ferror() .
else if (result == EOF) { if (feof(stdin)) { } if (ferror(stdin)) {
To answer your question: what will promptChar() return?
It will return an undefined value of type char.
You can follow the example of a library function that processes characters and returns an int from promptChar() . This will be the value of the character read in unsigned char , or negative int ( EOF ) in case of an error. Read the description of fgetc() , for example.
source share