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


Please Help Members By Posting Answers For Below Questions

How are 16- and 32-bit numbers stored?

725


Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?

671


What is variables in c?

610


What's the difference between constant char *p and char * constant p?

659


What is the purpose of main( ) in c language?

624






Explain what is the difference between the expression '++a' and 'a++'?

628


What do you mean by keywords in c?

631


How can I swap two values without using a temporary?

619


What are the different types of pointers used in c language?

613


write a c programming using command line argument,demonstrate set operation(eg;union,intersection,difference) example output is c:>setop 12 34 45 1 union 34 42 66 c:>setop 12 34 1 42 66 c:>setop 12 34 diff 12 56 67 78 setop 12 34

1631


Write a program to replace n bits from the position p of the bit representation of an inputted character x with the one's complement. Method invertBit takes 3 parameters x as input character, p as position and n as the number of positions from p. Replace n bits from pth position in 8 bit character x. Then return the characters by inverting the bits.

3692


What are c identifiers?

630


Why do we use namespace feature?

584


Do string constants represent numerical values?

926


What functions are used for dynamic memory allocation in c language?

603