#include <stdio.h>
struct stringStats {
int stringLength;
int upperCaseCount;
int lowerCaseCount;
int digitCount;
int spaceCount;
int nonAlphanumericCount;
int vowelCount;
int nonVowelCount;
int specialCharacterCount;
int printableNonAlphanumericCount;
int hexDigitCount;
int octalDigitCount;
int binaryDigitCount;
int punctuatorCount;
int controlCharacterCount;
int printableCharacterCount;
};
struct stringStats getStringStats(char theString[]);
int main(void) {
// your code goes here
return 0;
}
struct stringStats getStringStats(char theString[]) {
struct stringStats statsHolder = {0}; // initialize all counts to zero
const char vowels[] = "AEIOUaeiou"; // vowels for comparison
// for each character in the string, determine it's qualities
// and add to the related totals, check for string null terminator
for (int i = 0; theString[i] != '\0'; i++) {
unsigned char c = (unsigned char)theString[i];
// number of characters...
statsHolder.stringLength++;
// number of upper case characters...
if (isupper(c
)) statsHolder.
upperCaseCount++; // number of lower case characters...
if (islower(c
)) statsHolder.
lowerCaseCount++;
// number of digits...
if (isdigit(c
)) statsHolder.
digitCount++;
// number of blank spaces...
// could use isblank(), but that includes tabs
if (c == ' ') statsHolder.spaceCount++; // only spaces, not tabs
// number of non-alphanumeric characters...
if (!isalnum(c
)) statsHolder.
nonAlphanumericCount++;
// Check vowel vs non-vowel (for alphabetic chars only)
// number of vowels (a,e,i,o,u)...
statsHolder.vowelCount++;
} else {
// numer of non-vowels...
statsHolder.nonVowelCount++;
}
}
// number of special characters...
// (same as punctuation)
if (ispunct(c
)) statsHolder.
specialCharacterCount++;
// number of printable characters that are
// neither alphanumeric nor a space...
// isprint() works, isgraph() more efficient, exits when space
statsHolder.printableNonAlphanumericCount++;
// number of hexadecimal "digits" (0 - 9 and A - F)...
if (isxdigit(c
)) statsHolder.
hexDigitCount++;
// number of octal digits (0 - 7)...
if (isdigit(c
) && c
>= '0' && c
<= '7') statsHolder.octalDigitCount++;
// number of binary digits (0 or 1)...
if (isdigit(c
) && (c
== '0' || c
== '1')) statsHolder.binaryDigitCount++;
// number of punctuation characters...
if (ispunct(c
)) statsHolder.
punctuatorCount++;
// number of control characters...
if (iscntrl(c
)) statsHolder.
controlCharacterCount++;
// number of printable characters...
if (isprint(c
)) statsHolder.
printableCharacterCount++; }
// structure
return statsHolder;
}