Wap to count the number of occurrences of a particular word in the string.



#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
    int a,b=0,count=1,i,j,c;
    char name1[1000],name2[1000];
    printf("enter the string \n");
    gets(name1);
    printf("enter the word that u want to search in the string\n");
    gets(name2);
    a=strlen(name2);
    for(i=0;name1[i]!='\0';i++)
    if(name1[i]==name2[0])
    {
        c=i,count=1;
        for(j=1;j<a;j++)
        if(name1[++c]==name2[j])
        count++;
        if(count==a)
        b++;

    }
    printf("the word occures %d times in the string",b);
    getch();
}

No comments:

Post a Comment

Implemet Stack in python

  class Stack : def __init__ ( self , data ): self . stack = [] if ( data ): self . stack . append ( da...