I ran into the need to pull information in a string of the format "blah.bleh.bloh" in ANSI C. Normally I would use strok () to execute this, but since I get this string through strtok and strtok are not thread safe, I cannot use this option.
I wrote a function to manually parse a string. Here is a snippet:
for(charIndex=0; charIndex < (char)strlen(theString); charIndex++)
{
if(theString[charIndex] == '.')
{
theString[charIndex] = '\0';
osi_string_copy_n(Info[currentInfoIndex], 1024, theString, charIndex + 1 );
currentInfoIndex++;
theString = &theString[charIndex + 1];
}
charIndex++;
}
As you can see, I am trying to find the first appearance of '.' and pay attention to the character index. Then I convert '.' to zero char and copy the first line to the array.
Then I want to change the pointer to start right after the delimiter was found, essentially giving me a new shorter line.
Sorry, I get an error:
theString = &theString[charIndex + 1];
Mistake:
error C2106: '=' : left operand must be l-value
? ? , - .
EDIT: :
char theString[1024] = {0};
, , 1024 .