entry -> data
holds
"key_string \0 value_string \0"
(that is, two concatenated and null terminated strings)
I want to pass the key and value into
kvstore_put(&(server ->store), key, value);
as arguments.
entry -> data
holds
"key_string \0 value_string \0"
(that is, two concatenated and null terminated strings)
I want to pass the key and value into
kvstore_put(&(server ->store), key, value);
as arguments.
You don't need to copy anything - it can all be done with pointers. Because it's null terminated, the input string can double as the key. The value can be set in a string pointer with:
char *pszValue = strchr (pszKeyString, 0)+1;
No copying, very simple implementation.
One example of the way:
#include <stdio.h>
#include <string.h>
void kvstore_put(char key_value[], char key[], char value[]){
strcpy(key, key_value);
strcpy(value, strchr(key_value, '\0') + 1);
}
int main(void){
char kv[] = "key\0value\0";
char key[sizeof kv];
char value[sizeof kv];
kvstore_put(kv, key, value);
puts(key);
puts(value);
return 0;
}
another way:
void kvstore_put(char key_value[], char key[], char value[]){
while(*key++ = *key_value++);
while(*value++ = *key_value++);
}