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 the parts of c program?
What are Macros? What are its advantages and disadvantages?
What is difference between array and pointer in c?
What is pointer & why it is used?
What is gets() function?
Why is c known as a mother language?
write a c program to calculate sum of digits till it reduces to a single digit using recursion
How is null defined in c?
Define recursion in c.
Write a code to achieve inter processor communication (mutual exclusion implementation pseudo code)?
What is string function in c?
What does it mean when a pointer is used in an if statement?
What the advantages of using Unions?
What do you mean by Recursion Function?
How the c program is executed?