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


Please Help Members By Posting Answers For Below Questions

What is the use of pointers in C?

612


what do u mean by Direct access files? then can u explain about Direct Access Files?

1637


What is a nested loop?

644


How can my program discover the complete pathname to the executable from which it was invoked?

658


What is the process to create increment and decrement stamen in c?

583






Explain about block scope in c?

657


Explain setjmp()?

651


What are the types of data types and explain?

665


What is data type long in c?

621


What are the scope of static variables?

597


What do you mean by c?

584


what is the structure pointer?

1642


find the value of y y = 1.5x+3 for x<=2 y = 2x+5 for x>2

1524


How can I automatically locate a programs configuration files in the same directory as the executable?

628


Do variables need to be initialized?

616