Chars /Struct and EEPROM

Hi there!

I'm very confused with char variables.
I have a struct

struct smsConfig
{
byte version;
byte smsMode;
char *times[10];
char *mobiles[4];
} config = {200, 1, {"15:00"}, {}};

I don't know if char's are declared rightly. I don't know if I can delcare something like char times[10]5];

What I want:
times: 10 rows and each row will contain from 1 to 5 chars. Example

config.times[0]="1";
config.times[1]="13:34";
config.times[2]="1:00"; //it's same with first row

mobiles: 4 rows and each row will contain from 10 to 12 chars. Example

config.mobiles[0]="6987654321";
config.mobiles[1]="306987654321";

I use the the Arduino Playground - EEPROMWriteAnything

The main problem is that I store the data, and on EEPROM read, char variables are not stored exactly or random chars are displayed.

commands are parsed through SMS message that is a String.

So what I have done

Version check

 Serial.begin(9600);
  while (!Serial);
  EEPROM_readAnything(0, config);
  //check if ever stored on EEPROM
  if (config.version != 200)
  {
    smsConfig config = {200, 1, {"15:00"}, {}}; //Write default
    EEPROM_writeAnything(0, config);
    Serial.println(F("Default Configuration loaded"));
  }
  byte c=0;     
  for (byte i = 0; i < countof(config.mobiles); i++)
        {
          //newValue = getValue(cmd, ' ', i); //spliting and returning substring ex:
           newValue="306978932198";
          if (newValue.length() > 9 && newValue.length() < 14)
          {
            if (newValue.substring(0, 1) == "+") newValue = newValue.substring(1); //remove +
            Serial.println("NewMobile["+String(c)+"]:" + newValue);
            config.mobiles[c] = string2char(newValue);
            c++;
            storeConfig = 1;
          }
        }

        if(storeConfig) EEPROM_writeAnything(0, config);

"NewValue" values parsed correctly: IMAGE PARSED VALUES but returns similar or cutted
IMAGE STORED VALUES

Same with times:
times issue IMAGE

In other words...

String to char does not work for me when is stored to epprrom

If don't pass string to config.mobiles

 and I write the value in the code works...is going crazy! Ex.
config.mobiles[0] ="value-10length"; 



I tried
config.mobiles[c] = string2char(newValue); //https://coderwall.com/p/zfmwsg/arduino-string-to-char
config.mobiles[c] = newValue.c_str();

no luck....


ANY CLUE?

It supposed EEPROM_writeAnything can write anything
struct smsConfig
{
 byte version;
 byte smsMode;
 char *times[10];
 char *mobiles[4];
} config = {200, 1, {"15:00"}, {}};

Do you REALLY want to be writing pointers to EEPROM? I don't think so. You need to decide how long each times entry can be, and make the array that big. You need to decide how long each mobiles entry can be, and make the array that big.

You need to make sure that the entire struct WILL fit in EEPROM.

Hi!
Thanks for replying to me.

I'm struggling with this issue many days.

I want to have max 10 "times" and max 4 "mobiles".

I need to loop the values, if you mean "pointers" the array pointer.

New sketch test Screenshot by Lightshot

Please suggest an other approach

If anyone what's to help, can run my sketch test

EEPROM_TEST_v1.zip (2.02 KB)

Don't post code in a zip file. I'm not going to download it, and I suspect many others won't either. Nor will I go following links away from this site, as far as I know they are simply 'click bait'.

There is a post at the top of the board entitled 'How to use this forum - please read', which will explain how to post your code. I think it's point 7.

OK.
you can simply open it with notepad, there is no security issue using zip.

Anyway... I found a working temporary solution

I tried to with long long type, but I had to many compiler error especially with serial.print.

So i split it on store and I merge on read...

So, the only thing left is to find a very big variable to keep 12 digits.
Also a function to convert the "long long" to string, because String(Long Long var) causes compiler error, something about "ambiguous"

So, the only thing left is to find a very big variable to keep 12 digits.

An array of 13 chars (to have room for the NULL terminator) will work just fine.

A char pointer will NOT.

Let's make a lesson...

String mobileInput="123456789123"; //
char mobile[13]; //this can store 12+NULL operator

How I can store multiple mobiles into a char var? I need something like:

mobile[0]=mobileInput.c_str();
mobile[1]=mobileInput2.c_str();

//The above code does not work

How I can store multiple mobiles into a char var?

You can't. You can't even store one string in a char var. You CAN store a string in a char ARRAY.

Now, if you think about it for 10 seconds, the solution to storing multiple numbers, where each number needs to be stored in an array, is to use an array of arrays, otherwise known as a 2D array.