/*********************************************************** * You can use all the programs on www.c-program-example.com * for personal and learning purposes. For permissions to use the * programs for commercial purposes, * contact [email protected] * To find more C programs, do visit www.c-program-example.com * and browse! * * Happy Coding ***********************************************************/ #include<stdio.h> #include<string.h> main() { int strln,wordln,i,j,k,flag,count=0; char str[200],word[20]; printf("Enter line of text:n"); gets(str); printf("Enter the word to count:n"); scanf("%s",word); strln=strlen(str); wordln=strlen(word); for(i=0;i<strln;i++) { if(str[i]==word[0]&&((str[i-1]==' '||i==0)&&(str[i+wordln]==' '||str[i+wordln]==''))) { for(flag=0,k=i+1,j=1;j<wordln;j++,k++) { if(str[k]==word[j]) { flag++; } } if(flag==wordln-1) { count++; } } } printf("Number of occurence of '%s' = %dn",word,count); }
Read more Similar C Programs Searching in C C Strings
You can easily select the code by double clicking on the code area above.
To get regular updates on new C programs, you can Follow @c_program
You can discuss these programs on our Facebook Page. Start a discussion right now,
Share this program with your Facebook friends now! by liking it