preferences.getstring with c-type char array
Posted: Fri Jan 26, 2024 2:32 pm
The preferences documentation points out that the function
requires the exact length of the stored char array or else it will fail. My string has a variable length, defined by user input. Of course the char array has a fixed length, but that's not what the function call expects.
On the other hand, the storage of that c-string requires a null terminated char array, hence I assume that the function
only stores the characters up to (including ??? - the doc doesn't tell, but the value returned by the put function will tell) the null character.
Since the actual length of the c-string is variable I have to save the length of the c-string separately in order to retrieve it later on. I don't want to use the Arduino String Class, which should work without knowing the length of the saved string.
Is there a way to retrieve c-strings without knowing their actual length - or perhaps to store a c-string of fixed length by padding the array with null characters (what a waste ...)?
I can get the length of a stored byte [] but not of a stored char[]???
- size_t getString(const char* key, char* value, size_t len);
On the other hand, the storage of that c-string requires a null terminated char array, hence I assume that the function
- size_t putString(const char* key, const char* value);
Since the actual length of the c-string is variable I have to save the length of the c-string separately in order to retrieve it later on. I don't want to use the Arduino String Class, which should work without knowing the length of the saved string.
Is there a way to retrieve c-strings without knowing their actual length - or perhaps to store a c-string of fixed length by padding the array with null characters (what a waste ...)?
I can get the length of a stored byte [] but not of a stored char[]???