/********************************************************
* CP-I Warmup 1999-2000
* Problem #4
*******************************************************/
/*
* Question:
*
* A long sentence terminated by a new line character('\n') is given as
* input to a C program. the sentence may contain alphabets, digits and
* special characters. You are required to write a C program that counts
* the number of alphabets, digits, blanks, tabs and other characters and
* output them in a suitable manner.
*
* Example: Input : Output them (:,*,; etc.) in a suitable manner!
* Output : Alphabets : 30
* Digits : 0
* Blanks : 7
* Tabs : 0
* Others : 9
*/
#include <stdio.h>
#define MAX_SIZE 50
main()
{
char string[MAX_SIZE];
int alph=0,digit=0,blank=0,tab=0,other=0;
int i=0,len=0;
printf("Give the sentence:\n");
scanf("%[^\n]",string);
len=strlen(string);
for(i=0;i<len;i++)
{
if(toupper(string[i])>='A' && toupper(string[i])<='Z')
{
alph++;
continue;
}
if(string[i]>='0' && string[i]<='9')
{
digit++;
continue;
}
switch(string[i])
{
case ' ':
blank++;
break;
case '\t':
tab++;
break;
default:
other++;
}
}
printf("Alphabets\t: %d\n",alph);
printf("Digits\t\t: %d\n",digit);
printf("Blanks\t\t: %d\n",blank);
printf("Tabs\t\t: %d\n",tab);
printf("Others\t\t: %d\n",other);
}