Entry* LocalStore::Create(HostID owner, const char* identifier, E_DATA_TYPE type) { if (identifier == NULL) { return NULL; } Category* category = &m_rootCategory; Entry* entry = NULL; //Create copy of string to tokenize. int identifierLen = strlen(identifier); char* identifierCopy = new char[identifierLen+1]; memcpy(identifierCopy, identifier, identifierLen); identifierCopy[identifierLen] = NULL; //Loop over tokens char* nextToken = NULL; char* token = strtok(identifierCopy, "."); while (token != NULL) { //The next token is retrieved first so that we know which one is the last one. nextToken = strtok(NULL, "."); //If we haven't reached the last token, then the current one is a category. if (nextToken != NULL) { category = category->CreateSubcategory(token);//Get or create the new category } //Otherwise we've reached the value and can create it. else { entry = category->CreateEntry(owner, identifier, type); } //Next token becomes current token for next loop iteration. token = nextToken; } delete[] identifierCopy; return entry; }