初级会员

- 积分
- 79
- 金钱
- 79
- 注册时间
- 2022-4-8
- 在线时间
- 82 小时
|

楼主 |
发表于 2023-1-30 23:17:47
|
显示全部楼层
精英板 发表于 2023-1-21 13:16
write_SD=f_open(&fnew,"0:/date1.txt", FA_OPEN_ALWAYS|FA_WRITE);break;
write_SD = f_lseek(&fnew,f_si ...
我按照你的代码写了个函数,但是只能写入4个字符,是什么原因?以下是我的代码:
- //写入内容到文件
- void testWrite(char *filePath, char *writeBuffer)
- {
- FIL fnew; //文件对象
- FRESULT write_SD; //fatfs返回代码
- UINT fnum;
- write_SD= f_open(&fnew,filePath, FA_OPEN_ALWAYS|FA_WRITE);
- write_SD= f_lseek(&fnew,f_size(&fnew));
- write_SD= f_write(&fnew, writeBuffer , sizeof(writeBuffer), &fnum);
- if(write_SD==FR_OK)
- printf("-testWrite: 写入成功!\r\n");
- else {
- printf("-testWrite: 写入失败!\r\n");
- }
- write_SD=f_close(&fnew);
- }
复制代码 |
|