#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
struct stringStats
{
int stringLength;
int upperCaseCount;
int lowerCaseCount;
int digitsCount;
int blankSpacesCount;
int nonAlphanumericCharsCount;
int vowelsCount; //lower or upper case, a,e,i,o,u
int nonVowelsCount; //lower or upper case
int specialCharactersCount;
// char* nonAlphanumericChars; // not counting spaces //malloc, pointers?, assign pointer using malloc
int xDigitCount; //number of hexadecimal "digits" - 0 through 9 & the letters A - F ... accept upper and lower case
int octalDigitsCount; //0-7
int binaryDigitsCount; //0 or 1
};
// function prototype to get started, or better, use pointers */
struct stringStats getStringStats (char theString[])
{
struct stringStats statsOfStr;
statsOfStr.
stringLength = strlen(theString
);// int *nonAlphanumericChars = malloc(statsOfStr.stringLength * sizeof(char)); //have to free memory at end of program
for (int i = 0; i < statsOfStr.stringLength; i++)
{
char currentChar = theString[i];
statsOfStr.upperCaseCount++;
}
statsOfStr.lowerCaseCount++;
}
statsOfStr.digitsCount++;
}
if (currentChar == ' ') {
statsOfStr.blankSpacesCount++;
}
statsOfStr.nonAlphanumericCharsCount++;
// if (currentChar != ' ') {
// *statsOfStr.nonAlphanumericChars = currentChar;
// statsOfStr.nonAlphanumericChars++;
// }
}
char lowerCurrentChar
= tolower(currentChar
); if (lowerCurrentChar == 'a' || lowerCurrentChar == 'e' || lowerCurrentChar == 'i' || lowerCurrentChar == 'o' || lowerCurrentChar == 'u') {
statsOfStr.vowelsCount++;
}
statsOfStr.nonVowelsCount++;
}
statsOfStr.specialCharactersCount++;
}
statsOfStr.xDigitCount++;
}
if (currentChar >= 0 && currentChar <= 7) {
statsOfStr.octalDigitsCount++;
}
if (currentChar == 0 || currentChar == 1) {
statsOfStr.binaryDigitsCount++;
}
}
// *statsOfStr.nonAlphanumericChars = 0; //null terminating this string
//free(statsOfStr.nonAlphanumericChars); //ask papa
return statsOfStr;
}
int main(void) {
struct stringStats stats = getStringStats ("e ");
printf("%d\n", stats.
stringLength); printf("%d\n", stats.
upperCaseCount); printf("%d\n", stats.
lowerCaseCount); printf("%d\n", stats.
digitsCount); printf("%d\n", stats.
blankSpacesCount); //messed up printf("%d\n", stats.
nonAlphanumericCharsCount); printf("%d\n", stats.
vowelsCount); printf("%d\n", stats.
nonVowelsCount); printf("%d\n", stats.
specialCharactersCount); // printf("%s\n", stats.nonAlphanumericChars);
printf("%d\n", stats.
xDigitCount); printf("%d\n", stats.
octalDigitsCount); printf("%d\n", stats.
binaryDigitsCount);
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2luY2x1ZGUgPHN0ZGxpYi5oPgojaW5jbHVkZSA8Y3R5cGUuaD4KCnN0cnVjdCBzdHJpbmdTdGF0cwp7CiAgICBpbnQgc3RyaW5nTGVuZ3RoOwogICAgaW50IHVwcGVyQ2FzZUNvdW50OwogICAgaW50IGxvd2VyQ2FzZUNvdW50OwogICAgaW50IGRpZ2l0c0NvdW50OwogICAgaW50IGJsYW5rU3BhY2VzQ291bnQ7CiAgICBpbnQgbm9uQWxwaGFudW1lcmljQ2hhcnNDb3VudDsKICAgIGludCB2b3dlbHNDb3VudDsgLy9sb3dlciBvciB1cHBlciBjYXNlLCBhLGUsaSxvLHUKICAgIGludCBub25Wb3dlbHNDb3VudDsgLy9sb3dlciBvciB1cHBlciBjYXNlCiAgICBpbnQgc3BlY2lhbENoYXJhY3RlcnNDb3VudDsKLy8gICAgY2hhciogbm9uQWxwaGFudW1lcmljQ2hhcnM7IC8vIG5vdCBjb3VudGluZyBzcGFjZXMgLy9tYWxsb2MsIHBvaW50ZXJzPywgYXNzaWduIHBvaW50ZXIgdXNpbmcgbWFsbG9jCiAgICBpbnQgeERpZ2l0Q291bnQ7IC8vbnVtYmVyIG9mIGhleGFkZWNpbWFsICJkaWdpdHMiIC0gMCB0aHJvdWdoIDkgJiB0aGUgbGV0dGVycyBBIC0gRiAuLi4gYWNjZXB0IHVwcGVyIGFuZCBsb3dlciBjYXNlCiAgICBpbnQgb2N0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udCsrOwogICAgICAgIH0KICAgICAgICBpZiAoIWlzYWxudW0oY3VycmVudENoYXIpKSB7CiAgICAgICAgICAgIHN0YXRzT2ZTdHIubm9uQWxwaGFudW1lcmljQ2hhcnNDb3VudCsrOwogICAgICAgICAgIC8vIGlmIChjdXJyZW50Q2hhciAhPSAnICcpIHsKICAgICAgICAgICAgICAgLy8gKnN0YXRzT2ZTdHIubm9uQWxwaGFudW1lcmljQ2hhcnMgPSBjdXJyZW50Q2hhcjsKICAgICAgICAgICAgICAgLy8gc3RhdHNPZlN0ci5ub25BbHBoYW51bWVyaWNDaGFycysrOwogICAgICAgICAgLy8gIH0KICAgICAgICB9CiAgICAgICAgY2hhciBsb3dlckN1cnJlbnRDaGFyID0gdG9sb3dlcihjdXJyZW50Q2hhcik7CiAgICAgICAgaWYgKGxvd2VyQ3VycmVudENoYXIgPT0gJ2EnIHx8IGxvd2VyQ3VycmVudENoYXIgPT0gJ2UnIHx8IGxvd2VyQ3VycmVudENoYXIgPT0gJ2knIHx8IGxvd2VyQ3VycmVudENoYXIgPT0gJ28nIHx8IGxvd2VyQ3VycmVudENoYXIgPT0gJ3UnKSB7CiAgICAgICAgICAgIHN0YXRzT2ZTdHIudm93ZWxzQ291bnQrKzsKICAgICAgICB9CiAgICAgICAgZWxzZSBpZiAoaXNhbHBoYShjdXJyZW50Q2hhcikpIHsKICAgICAgICAgICAgc3RhdHNPZlN0ci5ub25Wb3dlbHNDb3VudCsrOwogICAgICAgIH0KICAgICAgICBpZiAoaXNwdW5jdChjdXJyZW50Q2hhcikpIHsKICAgICAgICAgICAgc3RhdHNPZlN0ci5zcGVjaWFsQ2hhcmFjdGVyc0NvdW50Kys7CiAgICAgICAgfQogICAgICAgIGlmIChpc3hkaWdpdChjdXJyZW50Q2hhcikpIHsKICAgICAgICAgICAgc3RhdHNPZlN0ci54RGlnaXRDb3VudCsrOwogICAgICAgIH0KICAgICAgICBpZiAoY3VycmVudENoYXIgPj0gMCAmJiBjdXJyZW50Q2h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