Sorry , I am using an ancient compiler
#include <iostream.h>
#include <conio.h>
#include <ctype.h>
void main()
{
char s[6] = "mOh1t*";
int u = 0 , l=0 , d=0 , sp=0 , t = 0;
for (int x = 0 ; s[x] ; x++)
{
if (isupper(s[x]))
u++;
else if(islower(s[x]))
l++;
else if (isdigit(s[x]))
d++;
t++;
}
sp = t - (u+l+d);
cout<<"t:"<<t;
cout<<"u:"<<u;
cout<<"l:"<<l;
cout<<"d:"<<d;
cout<<"sp:"<<sp;
getch();
}
The above code clearly counts the number of alphabets(uppercase and lowercase) , number of digits and number of special characters in a string.
I was wondering if the same is possible without using if statements/ternary operator/switch case. If yes , could I get a lead ?
Kudos to HoosierEE for the answer
UPDATE: Would it be possible to do the same as hoosierEE's answer without using inbuilt functions?
- A C++ newbie looking to learn