I'm trying to write a program that i have to enter a word from the keyboard and then it will check how much times appears in a text file using the strcmp() function. here is my code. i can write the word but when i enter the enter button the program stops. anyone can help me to figured out whats going wrong?
#include "stdafx.h"
#include <string.h>
#include <stdio.h>
int main()
{
char input[20];
char string[20];
int num = 0;
FILE *text;
printf("Enter a word:\n");
scanf_s("%s\n", &input);
fopen_s(&text, "C:\\Users\\USER\\Documents\\Visual Studio 2015\\Projects\\ConsoleApplication8\\text.txt", "r");
if (text == NULL) {
printf("Failed to open file\n");
return (-1);
}
while (!feof(text))
{
fscanf_s(text, "%s", string);
if (!strcmp(string, input));
num++;
}
printf("we found the word %d times\n", num);
return 0;
}`