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 are terms in math?
What is string constants?
What is the difference between text files and binary files?
What are the restrictions of a modulus operator?
Who developed c language and when?
What is an expression?
Which is the best website to learn c programming?
Explain what is gets() function?
What are different types of pointers?
What is the explanation for prototype function in c?
When a c file is executed there are many files that are automatically opened what are they files?
find the value of y y = 1.5x+3 for x<=2 y = 2x+5 for x>2
Are the outer parentheses in return statements really optional?
What does the characters “r” and “w” mean when writing programs that will make use of files?
Explain what are the different file extensions involved when programming in c?