SD card reading with fopen()

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

SD card reading with fopen()

1,763 次查看
Curro
Contributor III

I'm trying to read a text file, 2k of dimension, form sd card, in ESDHC mode.

This is a part of my code:

 

void Schermata(char* percorso){

MQX_FILE_PTR fp;

unsigned char LOGO[2049];


  fp=fopen(percorso,"r");

  fscanf (fp, "%s", LOGO);
...  

...

  fclose(fp);

 

but in LOGO I find only the first 256 chars of the file.

Where is the mistake?

 

Many thanks and best regards,

Corrado

0 项奖励
回复
2 回复数

1,340 次查看
RobertSignum
Contributor I

Hi,

 

I would say it is because of some 'safery' limitation of fscanf.

 

Imagine what will happen if someone will provide file bigger than 2K - fscanf have no way of knowing the size of buffer and your application will crash flat ...

 

Also "%s" stops reading on space ..., so if LOGO includes space it will only return first word from it.

 

I would use fread instead of fscanf ...

 

Regards,

Robert

0 项奖励
回复

1,340 次查看
Curro
Contributor III

Many thanks Robert,

no spaces in my .txt but I think the problem is in fscanf "limitations"...

I'll try with fread instead.

Best regards,

Corrado

0 项奖励
回复