An alternative to Paul’s suggestions (with the benefit to not overshoot the array boundaries
)
int setEmail(const char* command) {
int retVal = strncpy(config_data.email, command, sizeof(config_data.email)-1);
...
return retVal; // use the return value to communicate something at least
// somewhat useful like the length of the actually copied string
// or the result of the storeConfigVariables() call
}
works just as well.
Additionally, if you ever want to wipe the content of the array entirely you can use
memset(config_data.email, 0, sizeof(config_data.email));
consequently I’d add this to storeConfigVariables()
bool storeConfigVariables(const char* email = NULL, bool cleanSlate = false) {
bool retVal = false;
if (cleanSlate) {
memset(config_data, 0, sizeof(config_data));
config_data.magic = DATA_MAGIC;
}
if (email) {
strncpy(config_data.email, email, sizeof(config_data.email)-1);
}
...
return retVal;
}