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
Whats s or c mean?
Explain argument and its types.
What is wrong in this statement?
Can one function call another?
Is javascript based on c?
Explain #pragma statements.
Explain how can I right-justify a string?
What does int main () mean?
Explain a file operation in C with an example.
Do pointers need to be initialized?
What is the acronym for ansi?
Why is c still so popular?
Is c procedural or functional?
What is the purpose of scanf() and printf() functions?
What are pointers really good for, anyway?