Check whether a given word exists in a file or not Program in C

Check whether a given word exists in a file or not Program in C
Check whether a given word exists in a file or not Program in C

WAP to check whether a given word exists in a file or not. If yes then find the number of times it occurs.

File contain lines:

how are you.
this is a boy
i am good
#include<stdio.h>
void main()
{     

	FILE* filePointer;
	int wordExist=0;
	int bufferLength = 255;
	char search[100];
	printf("Enter word to be search=");
	scanf("%s",search);
	char line[bufferLength];
	filePointer = fopen("D:\\file.txt", "r");
	while(fgets(line, bufferLength, filePointer))
	{
		char *ptr = strstr(line, search);
		if (ptr != NULL) 
		{
			wordExist=1;
			break;
		}
	}
	fclose(filePointer);
	if (wordExist==1)
	{
		printf("Word exists.");
	}
	else 
	{
		printf("Word doesn't exist.");
	}
}  

Output:

Enter word to be search=is
Word exists.
b. tech. bca c language tutorial learn c language study c language
Recent Posts