Given a string (as the argument to function), after a given combination of characters, I need to delete the sequence of zeros, if exits(it only necessarily to modify the string). For example, if the combination of characters is x+
, the string 20.301x+000005
must be converted to 20.301x+5
.
I tried this:
void convertStr(char *analysisBuffer)
{
char *exp;
if( (exp = strstr(analysisBuffer,"x+"))!=NULL||(exp = strstr(analysisBuffer,"X+"))!= NULL)
{
exp += 2;
char * zeroIt = exp;
while(*zeroIt == '0')
++zeroIt;
unsigned int x = exp - analysisBuffer;
analysisBuffer[x] = '\0';
strcat(analysisBuffer,zeroIt);
}
}
Can anyone advise me how to implement it correctly?