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
Can math operations be performed on a void pointer?
what is the role you expect in software industry?
What is the difference between the local variable and global variable in c?
What are the different properties of variable number of arguments?
What is c language in simple words?
Devise a program that inputs a 3 digit number n and finds out whether the number is prime or not. Find out its factors.
How to draw the flowchart for structure programs?
List the variables are used for writing doubly linked list program.
What's the right way to use errno?
What is the function of volatile in c language?
Are bit fields portable?
What is a loop?
I just typed in this program, and it is acting strangely. Can you see anything wrong with it?
What is void main ()?
What is hash table in c?