Какова функциональность fgetchar()? Нужно ли промывать стандартный ввод перед его использованием?
В следующем коде (только для эксперимента) функция fgetchar () принимает значение, присутствующее в системном буфере и, таким образом, завершается. Почему?
#include<stdio.h>
#include<conio.h>
int main()
{
printf("Here getch will take the value and it will not echo and will take without enter\n");
getch();
printf("Here getchar will take the value but it will echo on entering ");
getchar();
printf("Here getche will take the value but it will echo not on entering\n");
getche();/*fflush(stdin);*/
printf("now we are going to illustrate the usage of macros");
fgetchar();
}
Я читал, что fgetchar () работает подобно getchar (), единственное отличие состоит в том, что последний является макросом, это единственное отличие???
1 ответ
Насколько мне известно, единственная разница между fgetchar()
а также getchar()
является fgetchar()
это макрос, который вызывает системную функцию fgetc()
Вот что говорится на страницах руководства:
fgetc() reads the next character from stream and returns it as an
unsigned char cast to an int, or EOF on end of file or error.
getc() is equivalent to fgetc() except that it may be implemented as a
macro which evaluates stream more than once.
getchar() is equivalent to getc(stdin).