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
Write a code to remove duplicates in a string.
Is it better to bitshift a value than to multiply by 2?
Should a function contain a return statement if it does not return a value?
How many levels of indirection in pointers can you have in a single declaration?
What are the rules for identifiers in c?
why use "return" statement a) on executing the return statement it immediately transfers the control back to the calling program b) it returns the value present in the parentheses return, to the calling program c) a & b d) none of the above
Why ca not I do something like this?
Tell us two differences between new () and malloc ()?
What are the different types of objects used in c?
Explain how can I write functions that take a variable number of arguments?
What is the difference between functions abs() and fabs()?
Give me the code of in-order recursive and non-recursive.
What are preprocessor directives in c?
Which is the best website to learn c programming?
How variables are declared in c?