Manipulating C-strings with multiple null characters in memory -


i need search through chunk of memory string of characters, several of these strings have every character null separated, this:
"i. .a.m. .a. .s.t.r.i.n.g"
of '.'s being null characters. problem comes getting memory. i've tried several ways, instance:

 char* str2;   str2 = (char*)malloc(sizeof(char)*40);     memcpy((void*)str2, "123\0567\09abc", 12);     

will put following memory str2 points to: 123.7.9abc..
like
str2 = "123456789\0abcde\054321";
have str2 pointing block of memory looks 123456789.abcde,321 , wherein '.' null character, , ',' actual comma.

so inserting null characters cstrings doesn't work thought did, inserting newline character. encountered similar difficulties trying string library well. separate assignments, like:

 char* str;      str = (char*)malloc(sizeof(char)*40);    strcpy(str, "123");    strcpy(str+4, "abc");    strcpy(str+8, "abc");   

but not preferable, , believe problem lies in understanding of how c-style strings stored in memory. "abc\0123" doesn't go memory 61 62 63 00 31 32 33 (in hex). how stored, , how can store need to?

(i apologize not having set code in blocks, first time posting question, , somehow "four spaced" more difficult can handle apparently. thank you, luchian. see more newlines needed.)

if every other char contains null, have utf-16 encoded strings. process them accordingly , problems disappear.

assuming on windows, utf-16 common, use wchar_t* rather char* hold such strings. , use wide char string processing functions operate on such data. example, use wcscpy rather strcpy , on.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -