Using Values from an array to an object

Hello,
I am trying to write some strings to eeprom using put and get approach abd trying to use the value ofstored in an array to the custom object but it is nbot writing to epromm if I hard code the values to the object it works works
Here is my sample code

#include <EEPROM.h>
char LocoAddress[4][6] = {"1830", "3", "999", "4444"};
struct MyObject {
	char loc0[10];
	char loc1[10];
	char loc2[10];
	char loc3[10];
};

void setup() {

  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

    secondTest();
    writtoeprom();
  Serial.print("Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!");
}

void loop() {
  /* Empty loop */
}


void writtoeprom(){
   //float f = 123.456f;  //Variable to store in EEPROM.
  int eeAddress = 0;   //Location we want the data to be put.

/* this works 
MyObject customVar = {
    "BLABLA0",
   "BLABLA1",
    "BLABLA2",
	  "BLABLA3"
  };
  */
  
  MyObject customVar = {
    LocoAddress[0],
    LocoAddress[1],
    LocoAddress[2],
   LocoAddress[3]
  };

 // eeAddress += sizeof(float); //Move address to the next byte after float 'f'.

  EEPROM.put(eeAddress, customVar);
  //secondTest();
  Serial.print("Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!");
  
  
}

void secondTest() {
  int eeAddress = sizeof(float); //Move address to the next byte after float 'f'.

  MyObject customVar; //Variable to store custom object read from EEPROM.
  EEPROM.get(eeAddress, customVar);

  Serial.println("Read custom object from EEPROM: ");
  Serial.println(customVar.loc0);
  Serial.println(customVar.loc1);
  Serial.println(customVar.loc2);
  Serial.println(customVar.loc3);
}

I think you’re making this way too complicated.

// Ok first we describe it…
struct MyObject {
char loc0[10];
char loc1[10];
char loc2[10];
char loc3[10];
};

MyObject customVar; // Now we have one to play with.

load it like…

strcpy(customVar.loc0, “1830”);
strcpy(customVar.loc1, “3”);
.
.
.

then stuff this into the EEPROM like…

EEPROM.put(0, customVar);

Try that, cut out all the junk from your code you don’t understand. Its just confusing you more.

And for lord sakes, proof read your posts before posting!

-jim lee

jimLee:
I think you're making this way too complicated.

// Ok first we describe it..
struct MyObject {
char loc0[10];
char loc1[10];
char loc2[10];
char loc3[10];
};

MyObject customVar; // Now we have one to play with.

load it like..

strcpy(customVar.loc0, "1830");
strcpy(customVar.loc1, "3");
.
.
.

then stuff this into the EEPROM like..

EEPROM.put(0, customVar);

Try that, cut out all the junk from your code you don't understand. Its just confusing you more.

And for lord sakes, proof read your posts before posting!

-jim lee

Suggested solution fixed issue and Strcpy worked. I will post the code
Sorry about stupidly written post and posting it with proof reading it.

No worries! Glad you're up and running.

-jim lee