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 / ram
#include <string.h>
void main()
{
char name[] ="Dream as if you will live forever, live as if
you will die today";
char r[] ="live";
int iLen = strlen(r);
int iCount = 0;
while(1)
{
if( strstr(name,r) == NULL)
break;
strcpy(name, strstr(name,r));
strcpy(name,name+iLen);
iCount++;
}
printf("%d",iCount);
}
| Is This Answer Correct ? | 23 Yes | 28 No |
Post New Answer View All Answers
What is the meaning of 2d in c?
Can you mix old-style and new-style function syntax?
Can an array be an Ivalue?
Explain pointer. What are function pointers in C?
What is c method?
What is structure packing in c?
What is the explanation for cyclic nature of data types in c?
What is the purpose of the preprocessor directive error?
What is variable and explain rules to declare variable in c?
What is an identifier?
Explain the red-black trees?
What are dangling pointers in c?
what is a function method?give example?
How can I find out if there are characters available for reading?
How can a number be converted to a string?