I am faced with the need to pull out the information in a string of the format "blah.bleh.bloh" in ANSI C. Normally I would use strok() to accomplish this, but since I am getting this string via strtok, and strtok is not thread-safe, I cannot use this option.
I have written a function to manually parse the string. Here is a snippit:
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 try to find the first occurrence of '.' and make note of the index of the character. Then I convert the '.' to a null char and copy the first string to an array.
Then I want to change the pointer to start just after where the delimiter was found, essentially giving me a new shorter string.
Unfortunately I am getting an error on the line:
theString = &theString[charIndex + 1];
The error is:
error C2106: '=' : left operand must be l-value
Why am I not allowed to move the pointer like this? Is my method flawed? Perhaps someone has a better idea for me to parse this string.
EDIT: In response to the comments, the declaration for theString is:
char theString[1024] = {0};
Also, I am guaranteed that theString will never be more than 1024 characters.