Hello, I'm trying to create a program that counts the amount of alphabetical characters, numbers, blanks and total amount of characters in a string a user gets to enter. The user also quits the program manually by pressing CTRL + D (in linux terminal).
These are the results I get from the code so far by typing in "hello cplusplus 123 c++" CTRL + D.
1 2 3 4 5
The string had:
Alphabetical characters...: 0
Numbers...................: 0
Blanks....................: 3
Total amount of characters: 20
So I can't seem to find a way to count the amount of alphabetical characters and numeric characters. Can anyone help me out with this?
@MiiNiPaa I'm aware of the isalpha(), isdigit() and isspace() functions and that is basically why I declared cctype in the first place but I have no clue of how I'm supposed to use them.
Oh, ok. You have problem with input: cin >> tecken will not read whitespaces. You have attempt to handle that inside your function, but there is several ways to fail it. For example your input has 23 characters and 4 spaces.
I would suggest to read whole line by using getline() function.
Then iterate over resulting line and check current characte against all three functions:
1 2 3 4 5 6 7
for(int i = 0; i < line.size(); ++i) {
if( isspace(line[i]) )
++spaces;
if( isdigit(line[i]) )
++digits;
//...
}