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
When should structures be passed by values or by references?
How can I read data from data files with particular formats?
Why do we use main function?
Write a code on reverse string and its complexity.
What is the best organizational structure?
Is there any demerits of using pointer?
write a c program to find the largest and 2nd largest numbers from the given n numbers without using arrays
How can you increase the allowable number of simultaneously open files?
Subtract Two Number Without Using Subtraction Operator
what is the function of pragma directive in c?
what does static variable mean?
What is a newline escape sequence?
What is the difference between declaring a variable by constant keyword and #define ing that variable?
Explain what will the preprocessor do for a program?
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.