I have written the code below however the strcmp
function is not working properly. It is not picking up known text from a text file and returns 0
for the word count.
int count = 0;
char line[400];
char word[20];
printf("Search for? \n");
scanf_s("%s", word, 19);
if (Fp == NULL)
{
printf("File not found");
}
while (!feof(Fp))
{
fgets(line, 150, Fp);
if (strcmp(line, word) == 0) //searches the line to find word
{
count++;//increment
}
}
printf("Search returned %s was found %d number of times", word, count);