如何将每个char形成为块并写入文件 [英] How to form each char as chunk and write into file

查看:56
本文介绍了如何将每个char形成为块并写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我正在通过char从COM1端口char接收数据,我想从其他端口(COM3)捕获这些数据。

Hi!
I''m receiving data from COM1 port char by char and i would like to capture this data from other port(COM3).

LONG  CMainFrame::OnCommunication(WPARAM ch, LPARAM port)
{
    //getting data in ch. need write down in file chunk by chunk.
    WriteDataEx(m_strCapturePath,l_file, (char*)l_com_buffer,1024, FALSE);
}

WriteDataEx(const CString& f_strFilepath, CFile& f_file, char* cInput, const int f_size, BOOL bConfig)
{
    f_file.Write(cInput, f_size);
}



那么如何将每个字符组成块并发送到writedataex函数?


So how to form each chars as chunk and send to writedataex function ?

推荐答案

逻辑上你想要做的是创建一个静态缓冲区,它可以容纳1KB的数据。



每个字符首先被添加到缓冲区。



如果缓冲区的当前大小小于块大小,请将其添加到块中。

如果缓冲区的大小达到块大小size,写入块数据。
Logically what you wish to do is to create a static buffer which can hold up to 1KB of data.

Each character is first added to the buffer.

If the current size of the buffer is less than the chunk size, add it to the chunk.
If the size of the buffer reaches the chunk size, write the chunk data.


这篇关于如何将每个char形成为块并写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆