How to count alphabets, numeric and special characters ?

Answer : In this example, we have to count digits, spaces, special…

How to count alphabets, numeric and special characters ?

In this example, we have to count digits, spaces, special characters and alphabets using C program.

[pastacode lang=”c” manual=”%23include%20%3Cstdio.h%3E%0A%20%0Aint%20main()%0A%7B%0A%20%20%20%20char%20%20%20%20str%5B100%5D%3B%0A%20%20%20%20int%20countDigits%2CcountAlphabet%2CcountSpecialChar%2CcountSpaces%3B%0A%20%20%20%20int%20counter%3B%0A%20%0A%20%20%20%20%2F%2Fassign%20all%20counters%20to%20zero%0A%20%20%20%20countDigits%3DcountAlphabet%3DcountSpecialChar%3DcountSpaces%3D0%3B%0A%20%0A%20%20%20%20printf(%22Enter%20a%20string%3A%20%22)%3B%0A%20%20%20%20gets(str)%3B%0A%20%0A%20%20%20%20for(counter%3D0%3Bstr%5Bcounter%5D!%3DNULL%3Bcounter%2B%2B)%0A%20%20%20%20%7B%0A%20%0A%20%20%20%20%20%20%20%20if(str%5Bcounter%5D%3E%3D’0’%20%26%26%20str%5Bcounter%5D%3C%3D’9′)%0A%20%20%20%20%20%20%20%20%20%20%20%20countDigits%2B%2B%3B%0A%20%20%20%20%20%20%20%20else%20if((str%5Bcounter%5D%3E%3D’A’%20%26%26%20str%5Bcounter%5D%3C%3D’Z’)%7C%7C(str%5Bcounter%5D%3E%3D’a’%20%26%26%20str%5Bcounter%5D%3C%3D’z’))%0A%20%20%20%20%20%20%20%20%20%20%20%20countAlphabet%2B%2B%3B%0A%20%20%20%20%20%20%20%20else%20if(str%5Bcounter%5D%3D%3D’%20′)%0A%20%20%20%20%20%20%20%20%20%20%20%20countSpaces%2B%2B%3B%0A%20%20%20%20%20%20%20%20else%0A%20%20%20%20%20%20%20%20%20%20%20%20countSpecialChar%2B%2B%3B%0A%20%20%20%20%7D%0A%20%0A%20%20%20%20printf(%22%5CnDigits%3A%20%25d%20%5CnAlphabets%3A%20%25d%20%5CnSpaces%3A%20%25d%20%5CnSpecial%20Characters%3A%20%25d%22%2CcountDigits%2CcountAlphabet%2CcountSpaces%2CcountSpecialChar)%3B%0A%20%0A%20%20%20%20return%200%3B%0A%7D” message=”” highlight=”” provider=”manual”/]

Output :

[pastacode lang=”c” manual=”Enter%20a%20string%3A%20wikitechy%2C%20789%40%23%2512.%0A%0ADigits%3A%205%0AAlphabets%3A%209%0ASpaces%3A%201%0ASpecial%20Characters%3A%205″ message=”” highlight=”” provider=”manual”/]
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like