新手入门
- 积分
- 11
- 金钱
- 11
- 注册时间
- 2020-6-17
- 在线时间
- 2 小时
|
1金钱
const char writeBuf[]="文件写入例子!";
char readBuf[4096]="";
写入的就是这个字符串 "文件写入例子!"
但为什么读取的时候是 “文件写入例子!?”
会多这样一个问号呢
还有就是当我 char readBuf[4096]="啊啊";
随便给接收的readBuf赋一个初始值的时候,就不会出现这个问号了,这是什么原理,求解答!
代码如下:
#include "stm32f10x.h"
#include "./usart/bsp_usart.h"
#include "./led/bsp_led.h"
#include "./flash/bsp_spi_flash.h"
#include "ff.h"
FATFS fsObejct;
FIL fp;
const char writeBuf[]="文件写入例子!";
char readBuf[4096]=" ";
UINT bw;
UINT br;
int main(void)
{
FRESULT res;
LED_GPIO_Config();
LED_BLUE;
USART_Config();
res = f_mount(&fsObejct,"1:",1);
printf("\n\t rse = %d",res);
if(res == FR_NO_FILESYSTEM)
{
res = f_mkfs("1:",0,0);
printf("res2 = %d",res);
res = f_mount(NULL,"1:",1);
res = f_mount(&fsObejct,"1:",1);
printf("res3 = %d",res);
}
res = f_open(&fp,"1:abcd.txt",FA_OPEN_ALWAYS|FA_WRITE|FA_READ);
if(res == FR_OK)
{
res = f_write (&fp,writeBuf,sizeof(writeBuf),&bw);
printf("\r\n bw = %d , wirtBuf = %s",bw,writeBuf);
if(res == FR_OK)
{
f_lseek(&fp,0);
res = f_read(&fp,readBuf,f_size(&fp),&br);
if(res == FR_OK)
{
printf("\r\n br = %d , readBuf = %s",br,readBuf);
}
f_close(&fp);
}
}
}
大神帮帮忙!
|
|