1-标准IO库提供的三种类型的buffering:
- Fully buffered(全缓冲)
- Line buffered(行缓冲)
- unbuffered(无缓冲):典型标准错误流
2-行缓冲会遇到的两个问题:
- 遇到新行符号前填满了buffer
- 所有line-buffered和
unbuffered
stream输入请求都会flush
line-buffered的输出流
3-三个标准流采用哪种buffering:
- 标准error总是
unbuffered
- 标准input/output 在
terminal device
的时候是line buffered
;否则是fully buffered
4-对于打开的流,有三种无形式IO(unformated IO):
Character-at-a-time I/O
. We canread
orwrite
one character at a time。Line-at-a-time I/O.
If we want toread
orwrite
a line at a time, we use fgets and fputs.Direct I/O
(binary I/O). This type of I/O is supported by thefread
andfwrite
functions. These two functions are often used forbinary files
where we read or write a structure with each operation.
5-getc
和fgetc
之间的差别?以及注意点?
getc
宏
fgetc
函数
1. getc
的参数一定不能是有副作用的表达式
2. 可以使用fgetc
的地址,作为函数指针传入其他function
3. 调用fgetc
消耗的时间比getc
长
6-一般文件的缓冲模式?
默认全缓冲
7-临时文件有哪些相关调用?
tmpnam,tempnam
tmpfile, mkstemp
8-tmpnam,tempname的缺点?
在返回唯一pathname和用该pathname创建临时文件之间有一段空隙。其他的进程可能在该空隙内用同样的pathname创建了文件。这样会导致严重的后果。