#include <cctype> // For character classification
#include <iostream>
struct StringStats {
int length;
int upperCase;
int lowerCase;
int digits;
int spaces;
int nonAlphaNumeric;
};
StringStats analyzeString(const char* str) {
StringStats stats = {0}; // Initialize all members to zero
while (*str != '\0') { // Loop until the null terminator
stats.length++;
if (isupper(*str)) stats.upperCase++;
else if (islower(*str)) stats.lowerCase++;
else if (isdigit(*str)) stats.digits++;
else if (isspace(*str)) stats.spaces++;
else if (!isalnum(*str)) stats.nonAlphaNumeric++;
str++; // Move to the next character
}
return stats;
}
int main() {
const char* testString = "Hello World! 123 @#";
StringStats stats = analyzeString(testString);
std::cout << "String Characteristics:\n"
<< "Length: " << stats.length << "\n"
<< "Uppercase: " << stats.upperCase << "\n"
<< "Lowercase: " << stats.lowerCase << "\n"
<< "Digits: " << stats.digits << "\n"
<< "Spaces: " << stats.spaces << "\n"
<< "Non-alphanumeric: " << stats.nonAlphaNumeric << "\n";
return 0;
}