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
what is a constant pointer in C
any function have arguments one or more OR not . it is compulsary a) any function compulsary have one or more arguments b) any function did not have arguments. It is not compulsary c) it is optional it is not compulsary d) none of the above
Explain data types & how many data types supported by c?
Hai sir, I had planned to write the NIC scientific engineer exam , plz post the sample question......
The number of measuring units from an arbitarary starting point in a record,area,or control block to some other point a) recording pointer b) offset c) branching d) none
Is python a c language?
Are enumerations really portable?
An arrangement of information in memory in such a way that it can be easily accessed and processed by a programming language a) string b) data structure c) pointers d) array
What is the meaning of 2d in c?
What is array in C
How do I use void main?
What are the difference between a free-standing and a hosted environment?
What is c mainly used for?
What is the difference between the local variable and global variable in c?
What do you mean by Recursion Function?