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 / vikas kumar from agra

i've try my level best ..plz run this program...but u don't
mistake in typing..100% output right...just try..


#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,s,oc=0;
char str[100],substr[30];
clrscr();
printf("\n enter string");
gets(str);
printf("\n enter substr");
gets(substr);
for(s=0;substr[s];s++)
for(i=0;str[i];i++)
{
if(str[i]==substr[0])
{
j=i;
k=0;
while(str[j]==substr[k] && srt[j]!='\0' && substr[k]!='\0')
{
j++;
k++;
}
if(k==s)
{
oc++;
}
printf("\n\t\t occurrence is %d",oc);
getch();
}

Is This Answer Correct ?    18 Yes 43 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

When should structures be passed by values or by references?

581


How can I read data from data files with particular formats?

599


Why do we use main function?

630


Write a code on reverse string and its complexity.

606


What is the best organizational structure?

637






Is there any demerits of using pointer?

625


write a c program to find the largest and 2nd largest numbers from the given n numbers without using arrays

1779


How can you increase the allowable number of simultaneously open files?

593


Subtract Two Number Without Using Subtraction Operator

352


what is the function of pragma directive in c?

620


what does static variable mean?

649


What is a newline escape sequence?

665


What is the difference between declaring a variable by constant keyword and #define ing that variable?

2696


Explain what will the preprocessor do for a program?

593


a number whose only prime factors are 2,3,5, and 7 is call humble number,,write a program to find and display the nth element in this sequence.. sample input : 2,3,4,11,12,13, and 100.. sample output : the 2nd humble number is 2,the 3rd humble number is 3,the 4th humble number is ,the 11th humble number is 12, the 12th humble number is 14, the 13th humble number is 15, the 100th humble number is 450.

4540