To find no. of alphabets, digits & white spaces in a string entered by user.

#include<stdio.h>
#include<string.h>
main()
{
int a,b,c=1,d=0,e=0,f=0,g=1;
char s1[100],s2[100];
printf("Enter a string\n");
gets(s1);

b=strlen(s1);
for(a=1;a<=b-1;a++)
{
if(isalpha(s1[a]))
{
c++;
}

if(isspace(s1[a]))
{
e++;
}
if(isdigit(s1[a]))
{
f++;
}
}
printf("Digits = %d, Alphabets = %d, Space = %d",f,c,e);

}

 

Output:

 

Enter a string

hi 55

Digits = 2, Alphabets = 2 & Space = 1

 

 

Leave a Reply

Your email address will not be published.