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 / ranjith kumar

#include<stdio.h>
//#include<conio.h>
void main()
{
int i=0,chr=0,sp=0,words=1,ss=0,digits=0;
char line[100],temp='a';
//clrscr();
printf("\nEnter the line:\n");
gets(line);

while(line[i]!='\0') //to check for string termination
{
if((line[i]>64&&line[i]<91)||(line[i]>96&&line[i]<123)) // ascii range of characters
chr++;
else
{
if(line[i]==32) //ascii value of space is 32
{
sp++;
if(temp!=32)
words++;
}
else
{
if(line[i]>47&&line[i]<58) //ascii range of digits
digits++;
else
ss++;
}
}
temp=line[i];
i++;
}
printf("\nNumber of characters = %d words = %d spaces %d special symbols = %d digits = %d",chr,words,sp,ss,digits);
}

Is This Answer Correct ?    7 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is variables in c?

610


Explain how does flowchart help in writing a program?

635


GIven a sequence of characters. How will you convert the lower case characters to upper case characters. ( Try using bit vector - sol given in the C lib -> typec.h)

685


What does it mean when the linker says that _end is undefined?

637


Difference between Function to pointer and pointer to function

635






what is the function of pragma directive in c?

627


What is the default value of local and global variables in c?

560


int main() { Int n=20,i; For(i=0;i<=n;i--) { Printf(“-“); Return 0;

1128


Is it better to bitshift a value than to multiply by 2?

661


What is a constant?

636


what are the program that using a two dimensional array that list the odd numbers and even numbers separately in a given 10 inputs values

1259


Which is best book for data structures in c?

600


Explain what will the preprocessor do for a program?

606


What's a good way to check for "close enough" floating-point equality?

629


Explain what is the benefit of using const for declaring constants?

617