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 / abhishek

#include<stdio.h>
#include<string.h>
main()
{
int i,occ=0;
char str[100],ch;
printf("enter string");
scanf("%s",str);
printf("enter character");
scanf("%s",ch);
for(i=0;str[i]!='\0';i++)
{
if(str[i]==ch)
{
occ+=1;
}
else
{
occ+=0;
}
}
printf("occurance of %s in %s is %d",ch str occ);
getch();
}

Is This Answer Correct ?    14 Yes 12 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

When is a void pointer used?

672


Explain what is the difference between null and nul?

650


PROGRAM TO WRITE CONTENTS OF 1 FILE IN REVERSE TO ANOTHER FILE,PROGRAM TO COPY 1 FILE TO ANOTHER BY SPECIFYING FILE NAMES AS COMMAND LINE

1464


What are c preprocessors?

672


What is int main () in c?

621






What is wrong in this statement?

601


Is c call by value?

599


What are local static variables? How can you use them?

642


C language questions for civil engineering

1235


What is malloc() function?

634


Write a progarm to find the length of string using switch case?

1607


What is && in c programming?

674


What is s or c?

591


What are the advantages of using linked list for tree construction?

639


What is volatile variable in c with example?

581