Program to calculate no. of alphabets, digits & white spaces using user defined functions along with pointers.

#include<stdio.h>
main()
{
    char str[100];
    int i,j,a=0,b=0,c=0;
    char *p,*q,*r;
    printf("Enter a string\n");
    gets(str);
    j=strlen(str);
    p=&str;
    for(i=0;i<=j-1;i++)
    {
        if(isalpha(*(p+i)))
        {
            a++;
        }
        if(isdigit(*(p+i)))
        {
            b++;
        }
       if(isspace(*(p+i)))
       {
           c++;
       }
    }
    printf("Alphabets - %d, Digits - %d & Spaces - %d",a,b,c);
}

 

OUTPUT [Click to enlarge]:

white space

Leave a Reply

Your email address will not be published.