Vijayalaksmi wants to check the number of times the word “ India” appears in a given
paragraph. Write a C program without using string function to do
#include <stdio.h>
#include <string.h>
int main()
{
int ctr=0,i,frequency=1;
int I,n,d,m,a,spc;
char str[100];
printf("\n\nFind the number of times the word 'india ' in any combination appears :\n");
printf("Input the string : ");
fgets(str,sizeof str,stdin);
ctr=strlen(str);
for(i=0;i<=ctr-5;i++)
{
m=(str[i]=='i'||str[i]=='I');
n=(str[i+1]=='n'||str[i+1]=='N');
d=(str[i+2]=='d'||str[i+2]=='D');
I=(str[i+3]=='i'||str[i+3]=='I');
a=(str[i+4]=='a'||str[i+4]=='a');
spc=(str[i+5]==' '||str[i+5]=='\0');
if ((m&&n&&d&&I&&a&&spc)==1)
frequency++;
}
printf("The frequency of the word \'india\' is : %d\n\n",frequency);
}
Comments
Leave a comment