When I open the temporary file I see that the word is replaced. The string in the main file is printed in the temporary file without any spaces.
How can I fix this?
while (!feof(ptr2))
{
strcpy(string, "\0");
fscanf(ptr2, "%s", string);
if (!strcmp(string, word)) // If match found
num++;
if (strstr(string, word))
{
r2 = string;
while (r1 = strstr(r2, word))
{
while (r2 != r1)
{
fputc(*r2, temp);
r2++;
}
r1 = r1 + strlen(word);
fprintf(temp, "%s", word1);
r2 = r1;
}
while (*r2 != '\0') {
fputc(*r2, temp);
r2++;
}
}
else {
fputs(string, temp);
}