Put string in struct, Put struct and EEPROM, Then revers.

my project is a bedside clock that gets time and weather via the web. i have a nano and an ESP8266 module on hand and once i seal my clock up i wouldn’t want to have to take it apart again once i moved. i’m trying to store ssid,password,city,and country code on the ESP but if in the future where to program new credentials in it i wanted to use the nano as a proxy. i’m stuck on Strings and structs. i can get the values to input via Serial but there’s something going on in the saving and recovery of strings. i’ve tried to isolate this as much as possible, putting the essential code in its own sketch and plugging the serial monitor directly into the ESP. no error codes during compiling.
-Thanks

the code

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <WiFiUdp.h>
#include <EEPROM.h>

  struct myObject{
    String feild1;
    String feild2;
    String feild3;
    String feild4;
  };
  String ssid = "";
  String pass = "";  
  String city = "";
  String country = "";
  int actionCode = 0;
void setup() {
  Serial.begin(9600);
  while(!Serial.available()){}

  actionCode = Serial.parseInt();

  if(actionCode == 100){
    Serial.println();
    delay(1000);
    while(Serial. read() >= 0) ; 
    Serial.print("SSID: ");
    while(!Serial.available()){}
    ssid = Serial.readString();
    Serial.println(ssid);
    
    Serial.print("Password: ");
    while(!Serial.available()){}
    pass = Serial.readString();
    Serial.println(pass);
    
    Serial.print("City: ");
    while(!Serial.available()){}
    city = Serial.readString();
    Serial.println(city);
    
    Serial.print("Contry code: ");
    while(!Serial.available()){}
    country = Serial.readString();
    Serial.println(country);
    
    myObject wifiStuff = {
      ssid,
      pass,
      city,
      country
    };
    EEPROM.put(0, wifiStuff);
  }
  
  myObject wifiStuffRetrieve;
  EEPROM.get(0, wifiStuffRetrieve);
  ssid = wifiStuffRetrieve.feild1;
  pass = wifiStuffRetrieve.feild2;
  city = wifiStuffRetrieve.feild3;
  country = wifiStuffRetrieve.feild4;


Serial.print("ssid: ");
Serial.println(ssid);
Serial.print("password: ");
Serial.println(pass);
Serial.print("city: ");
Serial.println(city);
Serial.print("country: ");
Serial.println(country);
Serial.println("");
  
  WiFi.begin(ssid,pass);
  Serial.print("connecting");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("WiFi Connected");
  printWiFiStatus();

  Serial.print("xxCONECTEDxx");

  
}
void loop(){
  
  int actionCode = Serial.parseInt();
  if(actionCode == 100 || actionCode == 200){
    Serial.print("xxCONECTEDxx");
  }
  
  
  
  }

  void printWiFiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

the monitor

4⸮!⸮⸮⸮⸮OAqr⸮⸮     //<<<< garbage from restarting the ESP8266
SSID: funny        //<<<< these are prompts like "SSID" then wait,
                         // the "funny" was the example which was echoed
Password: stuff

City: liberty

Country code: us

ssid:                //<<<<< these should be populated by the inputs above
password: 
city: 
country: 

connectingWiFi Connected
SSID: "the ssid that shows here is old and this does not change with new entries"
IP Address: 192.168.0.28
signal strength (RSSI):-55 dBm
xxCONECTEDxx

You should use normal characters arrays and reserve a maximum size for them in the struct.

The String is a class. The object of that class does not contain the characters. It contains a "char * buffer" pointer which points to allocated memory in the heap.
This is the pointer in the String class: ArduinoCore-API/String.h at master · arduino/ArduinoCore-API · GitHub.

ok so i tried to edit my code and since this is my first experience using structs i might be missing something obvious. its throwing a error message.

array must be initialized with a brace-enclosed initializer

I double checked all my braces and there where there supposed to be so i don’t understand where this error is coming from.

line 73 is highlighted

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <WiFiUdp.h>
#include <EEPROM.h>

  struct myObject{
    char feild1[26];
    char feild2[26];
    char feild3[26];
    char feild4[11];
  };
  char c = 'x';
  char ssid[26];
  char pass[26];  
  char city[26];
  char country[11];
  int actionCode = 0;
void setup() {
  Serial.begin(9600);
  while(!Serial.available()){}

  actionCode = Serial.parseInt();

  if(actionCode == 100){
    Serial.println();
    delay(1000);
    int count = 0;
    while(Serial. read() >= 0) ; 
    Serial.print("SSID: ");
    while(!Serial.available()){}
    while(Serial.available()){
      c = Serial.read();
      ssid[count] = c;
      count++;
    }
    Serial.println(ssid);

    count = 0;
    Serial.print("Password: ");
    while(!Serial.available()){}
    while(Serial.available()){
      c = Serial.read();
      pass[count] = c;
      count++;
    }
    Serial.println(pass);

    count = 0;
    Serial.print("City: ");
    while(!Serial.available()){}
    while(Serial.available()){
      c = Serial.read();
      city[count] = c;
      count++;
    }
    Serial.println(city);

    count = 0;
    Serial.print("Country code: ");
    while(!Serial.available()){}
    while(Serial.available()){
      c = Serial.read();
      country[count] = c;
      count++;
    }
    Serial.println(country);
    
    myObject wifiStuff = {
      ssid,
      pass,
      city,
      country
    };                                      //<<<<HIGHLIGHTED LINE!!
    EEPROM.put(0, wifiStuff);
  }
  
  myObject wifiStuffRetrieve;
  EEPROM.get(0, wifiStuffRetrieve);
  ssid = wifiStuffRetrieve.feild1;
  pass = wifiStuffRetrieve.feild2;
  city = wifiStuffRetrieve.feild3;
  country = wifiStuffRetrieve.feild4;


Serial.print("ssid: ");
Serial.println(ssid);
Serial.print("password: ");
Serial.println(pass);
Serial.print("city: ");
Serial.println(city);
Serial.print("country: ");
Serial.println(country);
Serial.println("");
  
  WiFi.begin(ssid,pass);
  Serial.print("connecting");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("WiFi Connected");
  printWiFiStatus();

  Serial.print("xxCONECTEDxx");

  
}
void loop(){
  
  int actionCode = Serial.parseInt();
  if(actionCode == 100 || actionCode == 200){
    Serial.print("xxCONECTEDxx");
  }
  
  
  
  }

  void printWiFiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

I tweaked your code to look like this:

    Serial.println(country);
    struct myObject wifiStuff =
    {
      /*
      ssid,
      pass,
      city,
      country
      */
      "a","b","c","d"
    };                                      //<<<<HIGHLIGHTED LINE!!
    EEPROM.put(0, wifiStuff);
  }
  myObject wifiStuffRetrieve;
  EEPROM.get(0, wifiStuffRetrieve);
  ssid = wifiStuffRetrieve.feild1;
  pass = wifiStuffRetrieve.feild2;
  city = wifiStuffRetrieve.feild3;
  country = wifiStuffRetrieve.feild4;

The struct compiles as expected now, but the last line of the snippet fails with “invalid array assignment”. Which gives us the clue we need. You need to use strcpy to put or get strings into or out of the arrays in your structs.

There may be better ways to do it - initializer lists and constructors were mentioned.