Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int main()
- {
- char str[]="ab ab abc";
- char word[]="ab";
- int lens=0,lenw=0,i,j,count=0,c=0;
- //finding length of string and word
- while(str[lens] !='\0')
- {
- lens++;
- }
- while(word[lenw] !='\0')
- {
- lenw++;
- }
- for(i=0;i<lens;i++)
- {
- if(str[i]==word[0])
- {
- for(j=0;j<lenw;j++)
- {
- if(str[i+j]==word[j])
- {
- count++;
- }
- }
- if(count==lenw)
- {
- //here c stores the number of times the word is repeated in the string.
- c++;
- count=0;
- }
- }
- }
- printf("%d",c);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement