Hello all,
My simple function will get a substring in a provided string that recognized by starting and ending string.
Example: GetSubString("abcdefghijklmn", // source string
"def", // starting string
"klm" // ending string) will return "ghij"
My code like this:
char* GetSubString(char* cSource, char* cStart, char* cEnd)
{
char* cTemp;

cTemp = strstr(cSource, cStart);
int iStart = cTemp - cSource + strlen(cStart);

cTemp = strstr(cSource, cEnd);
int iEnd = cTemp - cSource - 1;

for (int i=iStart; i<=iFinish; i++)
cTemp[i-iStart] = cSource[i];

char* cResult = (char*) malloc(strlen(cTemp));
cResult = cTemp;
return cResult;
}
The length of substring I got is always more than the desired. I dont understand why it is? Have anybody point it out?
Thank you very much.