Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Pseudo-Code:</p> <blockquote> <p>Step 1: Scan forward until the first "\", note the index.</p> <p>Step 2: Scan Backward from the end to the last "\" (the first "\" encountered when going backwards), note the index.</p> <p>Step 3: StrCpy the relevant pieces out into 3 strings.</p> </blockquote> <p>Code: (does not rely on strrchr, or other methods you seem to have issues with)</p> <pre><code>void ParseRegEntry(char* regKey, char** TopLevel, char** Path, char** Key); int main(void) { char* regKey = "HKEY_CURRENT_USER\\Software\\MyProgram\\SomeOtherValue\\SomeKey"; char* TopLevel; char* Path; char* Key; ParseRegEntry(regKey, &amp;TopLevel, &amp;Path, &amp;Key); printf("1: %s\n2: %s\n3: %s\n", TopLevel, Path, Key); free(TopLevel); free(Path); free(Key); return 0; } void ParseRegEntry(char* regKey, char** TopLevel, char** Path, char** Key) { int firstDelimiter = 0; int lastDelimiter = strlen(regKey)-1; int keyLen; while(regKey[firstDelimiter] != '\\') { firstDelimiter++; } while(regKey[lastDelimiter] != '\\') { lastDelimiter--; } keyLen = strlen(regKey) - lastDelimiter-1; *TopLevel = (char*)malloc(firstDelimiter+1); strncpy(*TopLevel, regKey, firstDelimiter); (*TopLevel)[firstDelimiter] = '\0'; *Path = (char*)malloc(lastDelimiter - firstDelimiter+2); strncpy(*Path, regKey+firstDelimiter, lastDelimiter - firstDelimiter); (*Path)[lastDelimiter-firstDelimiter] = '\0'; *Key = (char*)malloc(keyLen+1); strncpy(*Key, regKey+lastDelimiter+1, keyLen); (*Key)[keyLen] = '\0'; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload