// **************************************************
// Function: getStringStats
//
// Description: analyzes a string and counts different
//              types of characters
//
// Parameters: s[] - input string
//
// Returns: structure containing all counts
//
// **************************************************

#include <stdio.h>
#include <ctype.h>

// structure definition
struct stringStats
{
    int stringLength;
    int upperCaseCount;
    int lowerCaseCount;
    int digitCount;
    int spaceCount;
    int nonAlnumCount;
    int vowelCount;
    int nonVowelCount;
    int specialCharCount;
    int symbolCount; //placeholder name
    int hexCount;
    int octalCount;
    int binaryCount;
    int punctCount;
    int controlCount;
    int printableCount;
};

// function prototype
struct stringStats getStringStats(char s[]);

int main()
{
    char input[100];
    struct stringStats result;

    // get input from user
    printf("Enter a string: ");
    fgets(input, sizeof(input), stdin);

    // call function
    result = getStringStats(input);

    // display results
    printf("\nString Length: %d", result.stringLength);
    printf("\nUppercase: %d", result.upperCaseCount);
    printf("\nLowercase: %d", result.lowerCaseCount);
    printf("\nDigits: %d", result.digitCount);
    printf("\nSpaces: %d", result.spaceCount);
    printf("\nNon-Alphanumeric: %d", result.nonAlnumCount);
    printf("\nControl Characters: %d", result.controlCount);
    printf("\nPrintable Characters: %d", result.printableCount);
    printf("\nVowels: %d", result.vowelCount);
    printf("\nNon-Vowels: %d", result.nonVowelCount);
    printf("\nHex Digits: %d", result.hexCount);
    printf("\nOctal Digits: %d", result.octalCount);
    printf("\nBinary Digits: %d", result.binaryCount);
    printf("\nPunctuation: %d", result.punctCount);
    printf("\nSpecial Characters: %d\n", result.specialCharCount);

    return 0;
}

struct stringStats getStringStats(char s[])
{
    struct stringStats st = {0};
    int i = 0;

    while(s[i] != '\0')
    {
        char c = s[i];
        st.stringLength++;

        if(isupper(c)) st.upperCaseCount++;
        if(islower(c)) st.lowerCaseCount++;
        if(isdigit(c)) st.digitCount++;
        if(isspace(c)) st.spaceCount++;
        if(!isalnum(c)) st.nonAlnumCount++;
        if(iscntrl(c)) st.controlCount++;
        if(isprint(c)) st.printableCount++;

        if(isalpha(c))
        {
            char l = tolower(c);
            if(l=='a'||l=='e'||l=='i'||l=='o'||l=='u')
                st.vowelCount++;
            else
                st.nonVowelCount++;
        }

        if(isxdigit(c)) st.hexCount++;
        if(c >= '0' && c <= '7') st.octalCount++;
        if(c == '0' || c == '1') st.binaryCount++;
        if(ispunct(c)) st.punctCount++;
        if(ispunct(c)) st.specialCharCount++;

        i++;
    }

    return st;
}
