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

Give differences between - new and malloc() , delete and free() ?

618


what are the 10 different models of writing an addition program in C language?

1447


Explain the difference between strcpy() and memcpy() function?

603


Difference between strcpy() and memcpy() function?

690


Explain what is the use of a semicolon (;) at the end of every program statement?

746






how do you execute a c program in unix.

649


Why is c called a mid-level programming language?

737


Explain the advantages of using macro in c language?

590


What is wrong in this statement? scanf(“%d”,whatnumber);

735


What is the newline escape sequence?

599


string reverse using recursion

1823


in linking some of os executables are linking name some of them

1662


What is a void * in c?

604


Write a C program to accept a matrix of any size. Find the frequency count of each element in the matrix and positions in which they appear in the matrix

1530


i have a written test for microland please give me test pattern

2198