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 / aashik shrestha

#include<stdio.h>
#include<string.h>
int main()
{
char s[100];
char *p;
char s1[10];
char *q;
int i,m,j = 1,l,count = 0;

printf("Enter the text:");
gets(s);

printf("Enter the word you wanna count:");
gets(s1);

p = s;
q = s1;

l = strlen(s);
m = strlen(s1);
i = 0;

while(*(p+i)!='\0')
{
j = 0;m = 1;
while(*(p+i) != ' ' && *(q+j)!= '\0' && *(p+i)!= '\0')
{
if(*(p+i) != *(q+j)){
m= 0;
break;
}
i++;
j++;
}
if(*(p+i) == '\0')
{
break;
}

if(*(p+i) == ' '&& *(q+j) == '\0')
count++;
if(*(p+i)!= ' ')
{
i++;
}
i++;
}
if(m == 1)
count++;
printf("Total occurence of %d\n",count);
return 0;
}

Is This Answer Correct ?    4 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a pointer in c?

1418


What language is windows 1.0 written?

989


What is modeling?

1001


What is #define size in c?

1118


Explain how can I avoid the abort, retry, fail messages?

990


Write a C Program That Will Count The Number Of Even And Odd Integers In A Set using while loop

2107


What is a function in c?

1485


What is a good data structure to use for storing lines of text?

1033


What are the 4 types of organizational structures?

1031


What is structure pointer in c?

989


What does == mean in texting?

1213


Why malloc is faster than calloc?

1014


Add Two Numbers Without Using the Addition Operator

769


How can you convert integers to binary or hexadecimal?

979


typedef enum { html, java, javascript, perl, cgi } lang;The above statement defines a : a) Union b) User defined type c) Enumerated variable d) none

1162