Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- int cnt;
- char str[10000];
- void article_count(char *article)
- {
- int article_len=strlen(article);
- char *tmp_str=str; //we put our main string in another temporary string
- while(tmp_str=strstr(tmp_str,article{ //strstr will return first occurrence from any position to article,
- //if not found it will return null and loop will break
- cnt++; //if article found, increment counter variable cnt
- tmp_str+=article_len; //Already found the article, so we can skip that article length ,
- //and search again from that position to next article occurrence
- }
- }
- int main()
- {
- scanf("%[^\n]s",str);
- cnt=0;
- article_count("A ");
- article_count(" a ");
- article_count("An ");
- article_count(" an ");
- article_count("The ");
- article_count(" the ");
- printf("%d\n",cnt);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement