Actually, I realised that fixing the spurious warning for a line that doesn't end in a new line isn't that involved. We just need to introduce a bit of state:
Code:
size_t copyWithoutRemovedWord(FILE *output_fp,
FILE *input_fp,
const char *word_to_remove)
{
size_t remove_count = 0;
int partial_read = 0;
char buffer[BUFSIZ];
while (fgets(buffer, BUFSIZ, input_fp))
{
/* There is a potential bug when a line is too long to fit in the
buffer, so we shall warn the user if that condition occurs: */
if (partial_read)
{
fprintf(stderr,
"Warning: the word to remove might not be found as the "
"line was only partially read for the searching.\n");
}
partial_read = !strchr(buffer, '\n');
remove_count += removeAll(buffer, word_to_remove);
fputs(buffer, output_fp);
}
return remove_count;
}