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 meaning of 2d in c?

604


What are preprocessor directives in c?

630


Between macros and functions,which is better to use and why?

1565


What is abstract data structure in c?

519


What is the difference between scanf and fscanf?

656






#define f(g,h) g##h main O int i=0 int var=100 ; print f ("%d"f(var,10));} wat would be the output??

1539


what are enumerations in C

718


What are the storage classes in C?

619


What is clrscr ()?

633


Where are c variables stored in memory?

592


How will you print TATA alone from TATA POWER using string copy and concate commands in C?

916


Given an array of 1s and 0s arrange the 1s together and 0s together in a single scan of the array. Optimize the boundary conditions?

972


In C programming, what command or code can be used to determine if a number of odd or even?

618


What is the difference between functions getch() and getche()?

613


What is c preprocessor mean?

781