Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • A program to count the different types of characters in given string

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.71k
    Comment on it

    counting of different characters is done by using strlen(i.e string length) and arr denotes array. We use for loop to pass the ASCII code of alphabets from a to z.

       #include<stdio.h>
        #include<string.h>
        void main()
        {
            char arr[]="askjdfbajksdfkasdfhjkasdfh";
            char x;
            int l=strlen(arr);
            int i=0,j;
            int c=0,var=0;
            for(j=97;j<=122;j++)      //a=97,z=122
            {   
                //c=j;
                for(i=0;i<l-1;i++)
                {
                    if(arr[i]==j)
                    {
                        c++;
                    }   
                }
                //cout<<"No. of Occurence of "<<c<<"::"<<c; 
                    if(c>0)
                    {   
                                       var++;
                        printf("No. of Occurence of %c ::%d\n",j,c);
                    }   
    
                c=0;
            }
        printf("No. of type of characters:%d\n",var);
    
        }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: