buf.c
来自「unix环境高级编程的源代码」· C语言 代码 · 共 34 行
C
34 行
#include "ourhdr.h"
void pr_stdio(const char *, FILE *);
int
main(void)
{
FILE *fp;
fputs("enter any character\n", stdout);
if (getchar() == EOF)
err_sys("getchar error");
fputs("one line to standard error\n", stderr);
pr_stdio("stdin", stdin);
pr_stdio("stdout", stdout);
pr_stdio("stderr", stderr);
if ( (fp = fopen("/etc/motd", "r")) == NULL)
err_sys("fopen error");
if (getc(fp) == EOF)
err_sys("getc error");
pr_stdio("/etc/motd", fp);
exit(0);
}
void
pr_stdio(const char *name, FILE *fp)
{
printf("stream = %s, ", name);
/* following is nonportable */
if (fp->_flags & _IOLBF) printf("line buffered");
else if (fp->_flags & _IONBF) printf("unbuffered");
else /* if neither of above */ printf("fully buffered");
printf(", buffer flag = %d\n", fp->_flags & 0xff);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?