fwrite的4个参数到底是什么意思!!!
现在我有一个回调函数,用来接收服务器发送过来的实时视频流。
void __stdcall RawFrame(unsigned long _ulID,unsigned char* _ucData,int _iSize)
第二个参数是视频数据,第三个参数是视频数据长度。
现在我要用fwrite把视频流保存成文件,比如abc.rmvb,那么这4个参数该怎么填????
pFile = fopen("abc.rmvb", "w");//在外部创建一个文件 回调中:fwrite(???, ???, ???, pFile); //这前三个参数怎么填??? fseek(pTdDlg->pFile, 0, SEEK_SET);size_t fwrite( const void *buffer,//指向要写入数据的指针 size_t size,//写入数据的个数(就是你要写入几个,一个为1) size_t count,//写入数据的大小 FILE *stream //要写入文件的指针fopen所打开的指针);//也帮你注明一下吧
[解决办法]
fwrite(_ucData, 1, _iSize, pFile);
fwrite就是这么用的,问题是你fopen的时候要以二进制打开,应该是"wb",而不是"w"
[解决办法]
size 是写入数据item的长度
count是写入的次数
所以 fwrite(buf,1024,1,fp) 和 fwrite(buf,1,1024,fp) 效果上等价
[解决办法]
buffer
Pointer to data to be written.
size
Item size in bytes.
count
Maximum number of items to be written.
stream
Pointer to FILE structure.
Return Value
fwrite returns the number of full items actually written, which may be less than count if an error occurs. Also, if an error occurs, the file-position indicator cannot be determined. If either stream or buffer is a null pointer, the function invokes the invalid parameter handler, as described in Parameter Validation. If execution is allowed to continue, this function sets errno to EINVAL and returns 0.
Remarks
The fwrite function writes up to count items, of size length each, from buffer to the output stream. The file pointer associated with stream (if there is one) is incremented by the number of bytes actually written. If stream is opened in text mode, each carriage return is replaced with a carriage-return – linefeed pair. The replacement has no effect on the return value.
This function locks the calling thread and is therefore thread-safe. For a non-locking version, see _fwrite_nolock.
[解决办法]
这个问题你首先应该先msdn,再谷歌+百度,最后才csdn。
size_t fwrite(const void* buffer,size_t size,size_t count,FILE* stream);
注意:这个函数以二进制形式对文件进行操作,不局限于文本文件
返回值:返回实际写入的数据块数目
(1)buffer:是一个指针,对fwrite来说,是要输出数据的地址。
(2)size:要写入内容的单字节数;
(3)count:要进行写入size字节的数据项的个数;
(4)stream:目标文件指针。
(5)返回实际写入的数据项个数count
说明:写入到文件的哪里? 这个与文件的打开模式有关,如果是w+,则是从file pointer指向的地址开始写,替换掉之后的内容,文件的长度可以不变,stream的位置移动count个数;如果是a+,则从文件的末尾开始添加,文件长度加大,而且是fseek函数对此函数没有作用。
至于fclose要看你的整体的程序结构。