#include<stdio.h>
#include<conio.h>
void main()
{
int count=0,i,times=0,t,h,e,space;
char str[100];
clrscr();
puts(“Enter a string:”);
gets(str);
/*Traverse the string to count the number of characters*/
while (str[count]!=’\0′)
{
count++;
}
/*Finding the frequency of the word ‘the’*/
for(i=0;i<=count-3;i++)
{
t=(str[i]==’t'||str[i]==’T');
h=(str[i+1]==’h'||str[i+1]==’H');
e=(str[i+2]==’e'||str[i+2]==’E');
space=(str[i+3]==’ ‘||str[i+3]==’\0′);
if ((t&&h&&e&&space)==1)
times++;
}
printf(“Frequency of the word \’the\’ is %d\n”,times);
getch();
}
/*—————————————————–
Output
Enter a string:
The Teacher’s day is the birth day of Dr.S.Radhakrishnan
Frequency of the word ‘the’ is 2
———————————————————*/
Not Satisfied ? Just search & get the result
Related posts:
- C program to accept a string and a substring and check if the substring is present in the given string
- C Program to accept two strings and concatenate them i.e.The second string is appended to the end of the first string
- C Program to accepts two strings and compare them. Finally it prints whether both are equal, or first string is greater than the second or the first string is less than the second string
- c program to find the length of a string without using the built-in function
- C program to find the length of a string without using the built-in function also check whether it is a palindrome or not
