返回值
成功时此函数返回零,否则返回非零值。
示例
以下示例显示setvbuf()函数的用法-
#include <stdio.h>
int main () {
char buff[1024];
memset( buff, '\0', sizeof( buff ));
fprintf(stdout, "Going to set full buffering on\n");
setvbuf(stdout, buff, _IOFBF, 1024);
fprintf(stdout, "This is jc2182.com\n");
fprintf(stdout, "This output will go into buff\n");
fflush( stdout );
fprintf(stdout, "and this will appear when programm\n");
fprintf(stdout, "will come after sleeping 5 seconds\n");
sleep(5);
return(0);
}
让我们编译并运行上面的程序以产生以下结果。在这里,程序一直将输出缓冲到buff中,直到它面对首次调用fflush()为止,之后再次开始缓冲输出,最后休眠5秒钟。在程序出来之前,它将剩余的输出发送到STDOUT。
Going to set full buffering on
This is jc2182.com
This output will go into buff
and this will appear when programm
will come after sleeping 5 seconds