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 meaning of 2d in c?
What are preprocessor directives in c?
Between macros and functions,which is better to use and why?
What is abstract data structure in c?
What is the difference between scanf and fscanf?
#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??
what are enumerations in C
What are the storage classes in C?
What is clrscr ()?
Where are c variables stored in memory?
How will you print TATA alone from TATA POWER using string copy and concate commands in C?
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?
In C programming, what command or code can be used to determine if a number of odd or even?
What is the difference between functions getch() and getche()?
What is c preprocessor mean?