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
Differentiate between a structure and a union.
Are the outer parentheses in return statements really optional?
What is a string?
What is variable in c example?
What are the differences between new and malloc in C?
Explain how can I convert a number to a string?
write a c program for swapping two strings using pointer
Explain the use of #pragma exit?
Write a program to print fibonacci series using recursion?
Can variables be declared anywhere in c?
Why header file is used in c?
Explain how do you print an address?
How can I implement a delay, or time a users response, with sub-second resolution?
What is c programing language?
What does do in c?