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


Please Help Members By Posting Answers For Below Questions

Differentiate between a structure and a union.

770


Are the outer parentheses in return statements really optional?

581


What is a string?

670


What is variable in c example?

597


What are the differences between new and malloc in C?

612






Explain how can I convert a number to a string?

652


write a c program for swapping two strings using pointer

2098


Explain the use of #pragma exit?

701


Write a program to print fibonacci series using recursion?

591


Can variables be declared anywhere in c?

626


Why header file is used in c?

582


Explain how do you print an address?

661


How can I implement a delay, or time a users response, with sub-second resolution?

631


What is c programing language?

617


What does do in c?

612