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
How are 16- and 32-bit numbers stored?
Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?
What is variables in c?
What's the difference between constant char *p and char * constant p?
What is the purpose of main( ) in c language?
Explain what is the difference between the expression '++a' and 'a++'?
What do you mean by keywords in c?
How can I swap two values without using a temporary?
What are the different types of pointers used in c language?
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
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.
What are c identifiers?
Why do we use namespace feature?
Do string constants represent numerical values?
What functions are used for dynamic memory allocation in c language?