You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

27 lines
731 B
C++

#include <iostream>
using std::cout, std::endl;
void count_letters(char str[], int& n_letters, int& n_digits, int& n_other) {
while (*str) {
if (*str >= 'a' && *str <= 'z' || *str >= 'A' && *str <= 'Z') {
n_letters += 1;
}
else if (*str >= '0' && *str <= '9') {
n_digits += 1;
}
else {
n_other += 1;
}
str += 1;
}
}
int main() {
int n_letters = 0, n_digits = 0, n_other = 0;
char s[] = "1n!2y#3a$";
count_letters(s, n_letters, n_digits, n_other);
cout << "letters: " << n_letters << endl << "digits: " << n_digits << endl << "n_other: " << n_other << endl;
}