I am trying to make several calls to a function that returns a char array and have the returned char array assigned to a second char array.
Happy to provide code if necessary but I think I am just missing a syntax trick.
In setup:
strcpy (cSSID, get_config_value ( SSIDFilename );
Function:
char * get_config_value ( ConfigFilename )
char ConfigValue;
// Open file and get config data (ConfigValue)
return ConfigValue;
This seems logical to me but nothing is assigned to the char array variable cSSID when I do this.
I need to get four different config values for setting up wifi connection to server so I can save some memory by doing all the file reading in a function.
A better approach would be to pass the buffer as a parameter to your function
char cSSID[20]; // or whatever size you need
get_config_value ( SSIDFilename, "PARAM", cSSID );
Function:
bool get_config_value ( const char *ConfigFilename, const char *param, char *buffer )
// Open file and get config data and load it directly into buffer
return true; // we successfully loaded the value
It is left as an exercise for you to decide if you want to also pass the size of buffer and make sure you don't try to put too many chars into your buffer.
looks like your get_config_value() is expected to copy the contents of a file into a string and then the code separately copies that string to another string, cSSID.
why not pass a ptr to the destination string and have get_config_value() read the contents of the file directly into it?