#include <iostream>
using namespace std;
struct stringStats
{
int stringLength; // total characters
int upperCaseCount; // uppercase
int lowerCaseCount; // lowercase
int digitsCount; // digits
int spacesCount; // spaces
int nonAlnumCount; // non alphanumeric
int vowelsCount; // vowels
int nonVowelsCount; // non-vowels
int specialCharsCount; // special characters are nonalphanum and nonspace
int somePrintableCount; // all printable chars that are neither alphanumeric nor a space
int hexadecimalCount; // 0 to 7
int octalCount; // 0 to 9
int binaryCount; // 0 to 1
int punctuatorCount; // all printable characters that are neither alphanumeric nor a space
int controlCount; // between NUL & US, and DEL
int allPrintableCount; // all printable
};
// function prototype to get started, or better, use pointers */
struct stringStats getStringStats (char theString[]) {
struct stringStats stats = {0};
for (int i = 0; theString[i] != '\0'; i++){
char c = theString[i];
stats.stringLength++;
if(isupper(c))
stats.upperCaseCount++;
if(islower(c))
stats.lowerCaseCount++;
if(isdigit(c))
stats.digitsCount++;
if(isspace(c))
stats.spacesCount++;
if(!isalnum(c)) {
stats.nonAlnumCount++;
if(!isdigit(c)) // special characters are nonalphanum and nonspace
stats.specialCharsCount++;
}
if(isprint(c)) {
stats.allPrintableCount++;
if(!isalnum(c) && !isspace(c)) {
stats.somePrintableCount++; // neither alphanumeric nor a space
stats.punctuatorCount++;
}
}
if(c >= '0' && c <= '7')
stats.octalCount++;
if(c == '0' || c == '1')
stats.binaryCount++;
if((c >= 0 && c <= 31) || c == 127)
stats.controlCount++;
char lower = tolower(c);
if (isalpha(c)) {
if(lower == 'a' || lower == 'e' || lower == 'i' || lower == 'o' || lower == 'u')
stats.vowelsCount++;
else
stats.nonVowelsCount++;
}
char upper = toupper(c);
if((c >= '0' && c <= '9') || (upper >= 'A' && upper <= 'F'))
stats.hexadecimalCount++;
}
return stats;
}
int main() {
char inputString[500];
// Get input from the user
printf("Enter a string: ");
fgets(inputString, sizeof(inputString), stdin);
// Remove trailing newline character, if any
// Get the stats for the string
struct stringStats stats = getStringStats(inputString);
// Print the results
printf("\nString Analysis:\n");
printf("Total characters: %d\n", stats.stringLength);
printf("Uppercase characters: %d\n", stats.upperCaseCount);
printf("Lowercase characters: %d\n", stats.lowerCaseCount);
printf("Digits: %d\n", stats.digitsCount);
printf("Spaces: %d\n", stats.spacesCount);
printf("Non-alphanumeric characters: %d\n", stats.nonAlnumCount);
printf("Vowels: %d\n", stats.vowelsCount);
printf("Non-vowels: %d\n", stats.nonVowelsCount);
printf("Special characters: %d\n", stats.specialCharsCount);
printf("Printable characters (neither alphanumeric nor space): %d\n", stats.somePrintableCount);
printf("Hexadecimal digits: %d\n", stats.hexadecimalCount);
printf("Octal digits: %d\n", stats.octalCount);
printf("Binary digits: %d\n", stats.binaryCount);
printf("Punctuators (special printable characters): %d\n", stats.punctuatorCount);
printf("Control characters: %d\n", stats.controlCount);
printf("All printable characters: %d\n", stats.allPrintableCount);
return 0;
}