I want to write a function which removes certain word from text file. Program works fine but valgrind says something different:
==3411== Source and destination overlap in strcpy(0x51f1c90, 0x51f1c92)
==3411== at 0x4C2C085: strcpy (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3411== by 0x400AD7: DELTEword (remove2.c:113)
==3411== by 0x4009A1: main (remove2.c:73)
also when I am trying to remove for instance word: "go" sometimes it happens that word "ro" is also removed. Why?
Here's my code:
int DELTEword(char *word, char *KEYword)
{
int i, k = 0, l = 0, length;
char *ptr;
if(word != NULL)
{
length = strlen(KEYword);
for(i = 0; word[i] != '\0'; i++)
{
if(word[i] == KEYword[k])
{
l++;
k++;
}
if(l == length)
{
ptr = &word[i];
strcpy((ptr - length) + 1, ptr + 1);
l = 0;
k = 0;
}
}
return 1;
}
else return 0;
}