C code for counting chars,digits and special characters

counting number of chars, digits and special character
#include<stdio.h>
int main()
{
int i;
int character=0,digit=0,splchar=0;
char strr[20];
printf("Enter a string:\n");
gets(strr);
char *str=strr;//must
while(*str!='\0')
//for(i=0;i<strlen(strr);i++)
{
printf("%c\n",*str);
if(
( (*str>=65)&&(*str<=91 ))||
( (*str>=97)&&(*str<=123)) )
character++;
else if((*str>=48)&&(*str<=57))
digit++;
else
splchar++;

str++;
}
printf("Number of chars=%d\n",character);
printf("Number of digits=%d\n",digit);
printf("Number of splchar=%d\n",splchar);
printf("\n");
return 0;
}
/*
imanoj123!@#$$%^&*
m
a
n
o
j
1
2
3
!
@
#
$
$
%
^
&
*
Number of chars=5
Number of digits=3
Number of splchar=9
*/

No comments:

Post a Comment