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
Why is it that not all header files are declared in every C program?
What are the advantages of the functions?
What is #pragma statements?
Does c have class?
What is a static function in c?
#include
Is sizeof a keyword in c?
Explain what is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?
What is file in c preprocessor?
What's the right way to use errno?
Apart from dennis ritchie who the other person who contributed in design of c language.
What is the use of a ‘ ’ character?
Explain the difference between ++u and u++?
How to Throw some light on the splay trees?
How do you define CONSTANT in C?