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 / abhishek

#include<stdio.h>
#include<string.h>
main()
{
int i,occ=0;
char str[100],ch;
printf("enter string");
scanf("%s",str);
printf("enter character");
scanf("%s",ch);
for(i=0;str[i]!='\0';i++)
{
if(str[i]==ch)
{
occ+=1;
}
else
{
occ+=0;
}
}
printf("occurance of %s in %s is %d",ch str occ);
getch();
}

Is This Answer Correct ?    14 Yes 12 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can a program have two main functions?

584


What is string length in c?

622


‎How to define structures? · ‎

645


what is the c source code for the below output? 10 10 10 10 10 10 10 10 10 10 9 9 7 6 6 6 6 6 6 9 7 5 9 7 3 2 2 5 9 7 3 1 5 9 7 3 5 9 7 4 4 4 4 5 9 7 8 8 8 8 8 8 8 8 9

1446


What is the significance of scope resolution operator?

869






What is #include stdio h?

696


Explain bit masking in c?

646


When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999?

598


How to declare pointer variables?

696


what is the significance of static storage class specifier?

1675


Explain what is output redirection?

674


What is the benefit of using const for declaring constants?

600


Is null always defined as 0(zero)?

623


Explain enumerated types.

609


What is identifier in c?

558