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

a program that can input number of records and can view it again the record

1484


What is use of pointer?

587


Define the scope of static variables.

606


i got 75% in all semester am i eligible for your company

1737


Is null a keyword in c?

737






Write a program with dynamically allocation of variable.

604


What does *p++ do?

586


What is wrong with this program statement? void = 10;

820


Are negative numbers true in c?

600


in iso what are the common technological language?

1637


Explain bitwise shift operators?

632


What is typedef?

677


How can I generate floating-point random numbers?

606


What are conditional operators in C?

627


Draw a flowchart to produce a printed list of all the students over the age of 20 in a class .The input records contains the name and age of students. Assume a sentinel value of 99 for the age field of the trailer record

4742