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
What are the types of type specifiers?
What does it mean when a pointer is used in an if statement?
What are logical errors and how does it differ from syntax errors?
How to get string length of given string in c?
What are identifiers c?
Explain what is dynamic data structure?
Is it fine to write void main () or main () in c?
Explain what are linked list?
What is malloc return c?
Write the test cases for checking a variable having value in range -10.0 to +10.0?
How do we declare variables in c?
how to find binary of number?
What is calloc malloc realloc in c?
What is the c value paradox and how is it explained?
What are types of functions?