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 / balaji ganesh
#include<stdio.h>
#include<string.h>
void main()
{
char s[200],c[20],v=' ';
int i=0,j,f,n=0;
printf("enter string: ");
gets(s);
printf("enter new string: ");
gets(c);
while(i<strlen(s))
{
j=f=0;
while(j<strlen(c))
{
if(s[i++]!=c[j++])
{
f=1;i--;break;
}
}
if((f==0)&&(i==strlen(s)||s[i]==' ')&&(v==' '))
n++;
v=s[i++];
}
printf("the word %d times occured",n);
}
| Is This Answer Correct ? | 91 Yes | 41 No |
Post New Answer View All Answers
Explain what is the difference between a string and an array?
What happens if a header file is included twice?
Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?
Is it possible to execute code even after the program exits the main() function?
What is the best style for code layout in c?
What is preprocessor with example?
When should structures be passed by values or by references?
Read the following data in two different files File A: aaaaaaaadddddddd bbbbbbbbeeeeeeee ccccccccffffffff File B: 11111111 22222222 33333333 By using the above files print the following output or write it in the Other file as follows aaaaaaaa11111111dddddddd bbbbbbbb22222222eeeeeeee cccccccc33333333ffffffffffff
What is build process in c?
What is a buffer in c?
how should functions be apportioned among source files?
What is a MAC Address?
What are identifiers c?
What is LINKED LIST? How can you access the last element in a linked list?
Why is a semicolon (;) put at the end of every program statement?