Created
June 27, 2018 05:41
-
-
Save aligalehban/82d85864a9cba436b310ee1ace8d3989 to your computer and use it in GitHub Desktop.
separate alphabet, digit,space in string in c++ source code - www.alighalehban.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
char line[150]; | |
int vowels, consonants, digits, spaces; | |
vowels = consonants = digits = spaces = 0; | |
cout << "Enter a line of string: "; | |
cin.getline(line, 150); | |
for(int i = 0; line[i]!='\0'; ++i) | |
{ | |
if(line[i]=='a' || line[i]=='e' || line[i]=='i' || | |
line[i]=='o' || line[i]=='u' || line[i]=='A' || | |
line[i]=='E' || line[i]=='I' || line[i]=='O' || | |
line[i]=='U') | |
{ | |
++vowels; | |
} | |
else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z')) | |
{ | |
++consonants; | |
} | |
else if(line[i]>='0' && line[i]<='9') | |
{ | |
++digits; | |
} | |
else if (line[i]==' ') | |
{ | |
++spaces; | |
} | |
} | |
cout << "Vowels: " << vowels << endl; | |
cout << "Consonants: " << consonants << endl; | |
cout << "Digits: " << digits << endl; | |
cout << "White spaces: " << spaces << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment