Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

1. Write a C program to count the number of occurrence
of
a specific word in the given strings.
(for e.g. Find how many times the word “live” comes in the
sentence “Dream as if you’ll live forever, live as if
you’ll die today ”)

Answer Posted / balaji ganesh

#include<stdio.h>
#include<string.h>
void main()
{
char s[200],c[20],v=' ';
int i=0,j,f,n=0;
printf("enter string: ");
gets(s);
printf("enter new string: ");
gets(c);
while(i<strlen(s))
{
j=f=0;
while(j<strlen(c))
{
if(s[i++]!=c[j++])
{
f=1;i--;break;
}
}
if((f==0)&&(i==strlen(s)||s[i]==' ')&&(v==' '))
n++;
v=s[i++];
}
printf("the word %d times occured",n);
}

Is This Answer Correct ?    91 Yes 41 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Write a code of a general series where the next element is the sum of last k terms.

1010


What is volatile variable in c?

1067


What does %c do in c?

952


how do you programme Carrier Sense Multiple Access

1941


what is the different bitween abap and abap-hr?

2251


How do I get an accurate error status return from system on ms-dos?

1090


How can I recover the file name given an open stream?

974


Why n++ execute faster than n+1 ?

2893


What is file in c language?

976


What are keywords in c with examples?

1056


What is the hardest programming language?

1112


How is null defined in c?

1118


What are structural members?

970


What is the difference between struct and typedef struct in c?

1099


How do I create a directory? How do I remove a directory (and its contents)?

1123