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

what will be maximum number of comparisons when number of elements are given?

1406


How can I do graphics in c?

586


Define VARIABLE?

684


Q.1 write aprogram to stack using linklist o insert 40 items? Q.2 write a program to implement circular queue with help of linklist?

1594


Are enumerations really portable?

592






What is the advantage of a random access file?

637


Is it better to bitshift a value than to multiply by 2?

654


What is the meaning of c in c language?

592


When do we get logical errors?

633


How can a process change an environment variable in its caller?

648


List out few of the applications that make use of Multilinked Structures?

1284


What’s a signal? Explain what do I use signals for?

603


How can you determine the maximum value that a numeric variable can hold?

633


Differentiate between declaring a variable and defining a variable?

602


What is dynamic variable in c?

559