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

What is a program?

654


Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create.

1474


What is keyword with example?

628


Can include files be nested?

620


What are the features of c languages?

622






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

600


What are keywords c?

595


What are loops c?

610


What is the use of bit field?

629


What is calloc()?

623


What is quick sort in c?

577


What is dynamic memory allocation?

801


Do variables need to be initialized?

616


What are the two forms of #include directive?

639


What is c system32 taskhostw exe?

581