ffush的使用

fflush是标准C语言输入输出的拓展,它的作用是刷新输入输出流:
*对于输入流如stdin,调用fflush之后会清空输入缓冲区的内容。
*对于输出流如stdout,调用fflush之后会将输出缓冲区的内容写入到对应文件中。

#include <stdio.h>
#include <conio.h>

int main(void)
{
    int integer;
    char string[81];

    printf("Enter a sentence of four words with scanf: ");
    for (integer = 0; integer < 4; integer++)
    {
	scanf_s("%s", string, sizeof(string));
	printf("%s\n", string);
    }
    fflush(stdin);//此处如果不进行刷新流,那么下面的get_s语句将直接从缓冲区中得到数据,而不会在从命令行等待输入。
    printf("Enter the same sentence with gets: ");
    gets_s(string, sizeof(string));
    printf("%s\n", string);

}
原文地址:https://www.cnblogs.com/liujshi/p/5575885.html