fwrite
size_t fwrite ( const void * ptr, size_t size, size_t count, FILE * stream );
Write block of data to stream
Writes an array of
count elements, each one with a size of
size bytes, from the block of memory pointed by
ptr to the current position in the
stream.
The position indicator of the stream is advanced by the total number of bytes written.
Internally, the function interprets the block pointed by ptr as if it was an array of (size*count)
elements of type unsigned char
, and writes them sequentially to stream as if fputc was called for each byte.
说明:写入到文件的哪里? 这个与文件的打开模式有关,如果是w+,则是从file pointer指向的地址开始写,替换掉之后的内容,文件的长度可以不变,stream的位置移动count个数;如果是a+,则从文件的末尾开始添加,文件长度加大。
在调用fwrite函数后如果要调用fread函数,不会自动移到文件的头位置,你必须用fseek(fp,0),移动到文件头。