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
What is the use of pointers in C?
what do u mean by Direct access files? then can u explain about Direct Access Files?
What is a nested loop?
How can my program discover the complete pathname to the executable from which it was invoked?
What is the process to create increment and decrement stamen in c?
Explain about block scope in c?
Explain setjmp()?
What are the types of data types and explain?
What is data type long in c?
What are the scope of static variables?
What do you mean by c?
what is the structure pointer?
find the value of y y = 1.5x+3 for x<=2 y = 2x+5 for x>2
How can I automatically locate a programs configuration files in the same directory as the executable?
Do variables need to be initialized?