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 / balaji ganesh
#include<stdio.h>
#include<string.h>
void main()
{
char s[200],c[20],v=' ';
int i=0,j,f,n=0;
printf("enter string: ");
gets(s);
printf("enter new string: ");
gets(c);
while(i<strlen(s))
{
j=f=0;
while(j<strlen(c))
{
if(s[i++]!=c[j++])
{
f=1;i--;break;
}
}
if((f==0)&&(i==strlen(s)||s[i]==' ')&&(v==' '))
n++;
v=s[i++];
}
printf("the word %d times occured",n);
}
| Is This Answer Correct ? | 91 Yes | 41 No |
Post New Answer View All Answers
Write a code of a general series where the next element is the sum of last k terms.
What is volatile variable in c?
What does %c do in c?
how do you programme Carrier Sense Multiple Access
what is the different bitween abap and abap-hr?
How do I get an accurate error status return from system on ms-dos?
How can I recover the file name given an open stream?
Why n++ execute faster than n+1 ?
What is file in c language?
What are keywords in c with examples?
What is the hardest programming language?
How is null defined in c?
What are structural members?
What is the difference between struct and typedef struct in c?
How do I create a directory? How do I remove a directory (and its contents)?