std io的一个笔记

之前一直用fread和fwrite,但是一直没有认真看过manual page。这次看apue才发现,自己之前有个误解。

std io 操作

size_t fwrite(const void *BUF, size_t SIZE,
size_t COUNT, FILE *FP);

If `fwrite' succeeds in writing all the elements you specify, the
result is the same as the argument COUNT. In any event, the
result is the number of complete elements that `fwrite' copied to
the file.

从manual page可以看出,fwrite返回的是写入的个数COUNT,而不是SIZE*COUNT。之前一直误会了fwrite。
现在记下来以免再犯。

size_t fread(void *BUF, size_t SIZE, size_t COUNT,
FILE *FP);
fread返回值与fwrite同理。
The result of `fread' is the number of elements it succeeded in
reading.

原文地址:https://www.cnblogs.com/jojodru/p/2715015.html