SD card reading with fopen()

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

SD card reading with fopen()

1,657件の閲覧回数
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,234件の閲覧回数
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,234件の閲覧回数
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 件の賞賛
返信