// Assignment Final Question 5
//
// Name: <Maribel Fuentes>
//
// Class: C Programming, <Fall 2024>
//
// Date: <December 2, 2024>
#include <stdio.h>
#include <ctype.h>
// Define the structure
struct stringStats {
int stringLength;
int upperCaseCount;
int lowerCaseCount;
int digitCount;
int spaceCount;
int specialCharCount;
};
// Function prototype
struct stringStats getStringStats(char theString[]);
// Function definition
struct stringStats getStringStats(char theString[]) {
struct stringStats stats = {0, 0, 0, 0, 0, 0}; // Initialize all members to 0
int i = 0;
while (theString[i] != '\0') {
stats.stringLength++;
if (isupper(theString[i])) {
stats.upperCaseCount++;
} else if (islower(theString[i])) {
stats.lowerCaseCount++;
} else if (isdigit(theString[i])) {
stats.digitCount++;
} else if (isspace(theString[i])) {
stats.spaceCount++;
} else {
stats.specialCharCount++;
}
i++;
}
return stats;
}
// Main function
int main() {
char inputString[] = "Hello World! 123";
struct stringStats result = getStringStats(inputString);
printf("String Length: %d\n", result.stringLength);
printf("Uppercase Letters: %d\n", result.upperCaseCount);
printf("Lowercase Letters: %d\n", result.lowerCaseCount);
printf("Digits: %d\n", result.digitCount);
printf("Spaces: %d\n", result.spaceCount);
printf("Special Characters: %d\n", result.specialCharCount);
return 0;
}
Ly8gQXNzaWdubWVudCBGaW5hbCBRdWVzdGlvbiA1Ci8vCi8vIE5hbWU6IDxNYXJpYmVsIEZ1ZW50ZXM+Ci8vCi8vIENsYXNzOiBDIFByb2dyYW1taW5nLCA8RmFsbCAyMDI0PgovLwovLyBEYXRlOiA8RGVjZW1iZXIgMiwgMjAyND4KCiNpbmNsdWRlIDxzdGRpby5oPgojaW5jbHVkZSA8Y3R5cGUuaD4KCi8vIERlZmluZSB0aGUgc3RydWN0dXJlCnN0cnVjdCBzdHJpbmdTdGF0cyB7CiAgICBpbnQgc3RyaW5nTGVuZ3RoOwogICAgaW50IHVwcGVyQ2FzZUNvdW50OwogICAgaW50IGxvd2VyQ2FzZUNvdW50OwogICAgaW50IGRpZ2l0Q291bnQ7CiAgICBpbnQgc3BhY2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