Sunday, March 21, 2010

Bifurcate entered sentence into uppercase,lowercase,number,special characters & count at the end

/*End user enters sentence/s and you need to bifurcate each entered character whether its number,uppercase character,lower case character ,special character,whitespace character,tab/new line and then reprint the same sentence/s on new line*/

#include <stdio.h>
int main(void)
{
int i;
int big = 0,num = 0,sp = 0,small = 0,space = 0;
while ( (i = getchar()) != EOF )
{
if (( i >= 'a') && ( i <= 'z'))
small++;
else if (( i >= 'A') && ( i <= 'Z'))
big++;
else if (( i >= '0') && (i <= '9'))
num++;
else if ((( i >= 0) && (i <= 31)) || (( i >= 33) && ( i <= 47)) ||((i >= 58) && (i <= 64)) || (( i >= 91) && ( i <= 96)) || (( i >= 123) && ( i <= 127))) //special characters
sp++;
else if (( i == 32) || ( i == 9) || ( i = 10) || ( i = 13)) // for space,tab,newline
space++;
putchar(i);
}
printf("%d lower characters are entered \n",small);
printf("%d Uppercase characters are entered \n",big);
printf("%d White space characters are entered \n",space);
printf("%d Numerical characters are entered \n",num);
printf("%d Special characters are entered \n",sp);
return 0;
}