Here is the code,
Code:
bool isRotational(char* s1, char* s2)
{
int len = strlen(s1);
char* s = new char[2 * len + 1];
char* p = s1;
char* q = s;
while (*p)
{
*s++ = *p++;
}
p = s1;
while (*p)
{
*s++ = *p++;
}
*s = '\0';
int len2 = strlen(s2);
int j;
for (int i = 0; i<2 * len - len2 + 1; ++i)
{
for (j = 0; j < len2 && q[i + j] == s2[j]; ++j);
if (j == len2)
return true;
}
delete[] s;
return false;
}
I randomly found that the exception is caused by the statement delete[] s. But when I debug this code, the debugger won't point to the statement delete[] s at all. So I am just wondering how'd I find out the exception is caused by that? Secondly why is there an exception in the code that looks innocent? Thanks!