SD card reading with fopen()

cancel
Showing results for 
Search instead for 
Did you mean: 

SD card reading with fopen()

982 Views
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 Kudos
2 Replies

559 Views
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 Kudos

559 Views
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 Kudos