Code:
void DeleteString(char *chString, char *chDelString)
{
int nDelStringLength = 0;
while (chDelString[nDelStringLength] != 0)
++nDelStringLength;
for (int nStringDelCount = 0; chString[nStringDelCount]
!= 0; ++nStringDelCount)
if (chString[nStringDelCount] == chDelString[0])
{
int nStringDelCount2 = nStringDelCount + 1;
for (int nStringDelCount3 = 1; hDelString[nStringDelCount3] != 0; ++nStringDelCount3)
{
if (chString[nStringDelCount2] != chDelString[nStringDelCount3])
break;
if (chDelString[nStringDelCount3 + 1] == 0)
{
for (int nStringDelCount4 = 0; nStringDelCount4 <= nDelStringLength; ++nStringDelCount4)
{
int nStringDelCount5;
nStringDelCount5 = nStringDelCount + 1;
if (nStringDelCount4 == 0)
nStringDelCount5 = nStringDelCount;
while (chString[nStringDelCount5] != 0)
{
if (nStringDelCount5 == nStringDelCount && chString[nStringDelCount5 - 1] == 32)
for (int nStringDelCount6 = nStringDelCount - 1; chString[nStringDelCount6] != 0;
++nStringDelCount6)
{
chString[nStringDelCount6] = chString[nStringDelCount6 + 1];-------------
if (chString[nStringDelCount6 + 1] == 0)
{
--nStringDelCount5;
--nStringDelCount;
}
}
chString[nStringDelCount5] = chString[nStringDelCount5 + 1];
++nStringDelCount5;
--nStringDelCount;
}
}
}
++nStringDelCount2;
}
}
}
char *x = "a word and another word";
DeleteString(x, "word");
This is meant to remove any phrase that are labeled "word" plus any spaces before it. So when x is displayed on the screen, it should output "a and another". But, when it gets to the point in the function showed in ---... it tries to assign the space to the character next to it which in this case would be 'w' but the program breaks at that point and shows that it is an access violation. Does anyone know the solution to this problem?
