Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

When was c language developed?

1140


Write a program to display all the prime nos from 1 to 1000000, your code should not take time more than a minute to display all the nos.

2007


can any one please explain, how can i access hard disk(physical address)? it is possible by the use of far,near or huge pointer? if yes then please explain......

1808


What are the types of arrays in c?

1094


What is the role of this pointer?

993


How is actual parameter different from the formal parameter?

973


What is the code for 3 questions and answer check in VisualBasic.Net?

2100


Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?

1046


Tell me what is null pointer in c?

1012


 write a program that will open the file, count the number of occurences of each word in the the complete works of shakespeare.  You will then tabulate this information in another file.

2154


Tell me when would you use a pointer to a function?

1011


What is formal argument?

1092


Which built-in library function can be used to match a patter from the string?

1236


What is the difference between functions getch() and getche()?

1035


Where static variables are stored in c?

1041