rt-thread 的void cat(const char* filename)实现有一个地方有些疑问,求解
void cat(const char* filename){
rt_uint32_t length;
char buffer;
if (dfs_file_open(&fd, filename, DFS_O_RDONLY) < 0)
{
rt_kprintf("Open %s failed\n", filename);
return;
}
do
{
rt_memset(buffer, 0, sizeof(buffer)); //这里为什么要填充0呢,读数据到这个缓冲时不就覆盖调了;不知道这里是基于什么考虑呢???????
length = dfs_file_read(&fd, buffer, sizeof(buffer)-1 );
if (length > 0)
{
rt_kprintf("%s", buffer);
}
}while (length > 0);
dfs_file_close(&fd);
}
FINSH_FUNCTION_EXPORT(cat, print file) 好像是为了rt_kprintf("%s", buffer); 能识别吧 思考下
length = dfs_file_read(&fd, buffer, sizeof(buffer)-1 );
为什么要减1. 回复【2楼】aozima
-----------------------------------------------------------------------
字符串的标志是最后有一个0
页:
[1]