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
When should the register modifier be used? Does it really help?
Write a code to determine the total number of stops an elevator would take to serve N number of people.
What is the difference between array and linked list in c?
can anyone please tell about the nested interrupts?
find out largest elemant of diagonalmatrix
how to find anagram without using string functions using only loops in c programming
What is keyword with example?
What is const and volatile in c?
Why is c so important?
Do pointers need to be initialized?
How can I discover how many arguments a function was actually called with?
‘SAVEPOINT’ and ‘ROLLBACK’ is used in oracle database to secure the data comment. Give suitable examples of each with sql command.
What is the use of structure padding in c?
What is queue in c?
Can you please explain the difference between malloc() and calloc() function?