esp_spiffs.h need little bit of help

Kingstocks
Posts: 1
Joined: Tue Jun 04, 2024 1:33 pm

esp_spiffs.h need little bit of help

Postby Kingstocks » Fri Jun 07, 2024 3:21 am

Hi all,
I have try alot of thing to make it work
but I see it make a char as array but when I add a other char = the out I do not got the same data out

if anyone can help or point me in the right area


char dataout;
  1. void read_file_now(char *name, char *output) {
  2.     char oldData[64];
  3.     FILE* f = fopen(name, "r");
  4.     if (f == NULL) {
  5.         ESP_LOGE(TAG, "Failed to open file for reading");
  6.         return;
  7.     }
  8. int i = 0;
  9.      do{
  10.              char cx = fgetc(f);
  11.              if (feof(f)){
  12.                    break;
  13.              }
  14.         oldData[i] = cx;
  15.         i++;
  16.              ESP_LOGE(TAG, "%c", cx);
  17.          } while (1);
  18.        
  19.  
  20. printf("Final Data: %s\n", oldData);
  21. dataout = oldData;
  22.   fclose(f);
  23.  
  24. return;
  25.  ESP_LOGE(TAG, "We readed file %s", dataout );
I can see &%*$

Thank you all

ESP_Sprite
Posts: 9724
Joined: Thu Nov 26, 2015 4:08 am

Re: esp_spiffs.h need little bit of help

Postby ESP_Sprite » Fri Jun 07, 2024 7:20 am

If anything, oldData is not zero-terminated.

eriksl
Posts: 116
Joined: Thu Dec 14, 2023 3:23 pm
Location: Netherlands

Re: esp_spiffs.h need little bit of help

Postby eriksl » Mon Jun 10, 2024 3:18 pm

Nicely spotted.

Also I'd recommend to at least use block reads, like fread at file pointer level, or read at file descriptor level.

Who is online

Users browsing this forum: No registered users and 111 guests