fork download
  1. #include <stdio.h>
  2.  
  3. struct stringStats {
  4. int stringLength;
  5. int upperCaseCount;
  6. int lowerCaseCount;
  7. int digitCount;
  8. int spaceCount;
  9. int nonAlphanumericCount;
  10. int vowelCount;
  11. int nonVowelCount;
  12. int specialCharacterCount;
  13. int printableNonAlphanumericCount;
  14. int hexDigitCount;
  15. int octalDigitCount;
  16. int binaryDigitCount;
  17. int punctuatorCount;
  18. int controlCharacterCount;
  19. int printableCharacterCount;
  20. };
  21.  
  22. struct stringStats getStringStats(char theString[]);
  23.  
  24. int main(void) {
  25. // your code goes here
  26. return 0;
  27. }
  28.  
  29. struct stringStats getStringStats(char theString[]) {
  30. struct stringStats statsHolder = {0}; // initialize all counts to zero
  31. const char vowels[] = "AEIOUaeiou"; // vowels for comparison
  32.  
  33. // for each character in the string, determine it's qualities
  34. // and add to the related totals, check for string null terminator
  35. for (int i = 0; theString[i] != '\0'; i++) {
  36. unsigned char c = (unsigned char)theString[i];
  37.  
  38. // number of characters...
  39. statsHolder.stringLength++;
  40.  
  41. // number of upper case characters...
  42. if (isupper(c)) statsHolder.upperCaseCount++;
  43. // number of lower case characters...
  44. if (islower(c)) statsHolder.lowerCaseCount++;
  45.  
  46. // number of digits...
  47. if (isdigit(c)) statsHolder.digitCount++;
  48.  
  49. // number of blank spaces...
  50. // could use isblank(), but that includes tabs
  51. if (c == ' ') statsHolder.spaceCount++; // only spaces, not tabs
  52.  
  53. // number of non-alphanumeric characters...
  54. if (!isalnum(c)) statsHolder.nonAlphanumericCount++;
  55.  
  56. // Check vowel vs non-vowel (for alphabetic chars only)
  57. if (isalpha(c)) {
  58. if (strchr(vowels, c)) {
  59. // number of vowels (a,e,i,o,u)...
  60. statsHolder.vowelCount++;
  61. } else {
  62. // numer of non-vowels...
  63. statsHolder.nonVowelCount++;
  64. }
  65. }
  66.  
  67. // number of special characters...
  68. // (same as punctuation)
  69. if (ispunct(c)) statsHolder.specialCharacterCount++;
  70.  
  71. // number of printable characters that are
  72. // neither alphanumeric nor a space...
  73. // isprint() works, isgraph() more efficient, exits when space
  74. if (isgraph(c) && ispunct(c))
  75. statsHolder.printableNonAlphanumericCount++;
  76.  
  77. // number of hexadecimal "digits" (0 - 9 and A - F)...
  78. if (isxdigit(c)) statsHolder.hexDigitCount++;
  79.  
  80. // number of octal digits (0 - 7)...
  81. if (isdigit(c) && c >= '0' && c <= '7')
  82. statsHolder.octalDigitCount++;
  83.  
  84. // number of binary digits (0 or 1)...
  85. if (isdigit(c) && (c == '0' || c == '1'))
  86. statsHolder.binaryDigitCount++;
  87.  
  88. // number of punctuation characters...
  89. if (ispunct(c)) statsHolder.punctuatorCount++;
  90.  
  91. // number of control characters...
  92. if (iscntrl(c)) statsHolder.controlCharacterCount++;
  93.  
  94. // number of printable characters...
  95. if (isprint(c)) statsHolder.printableCharacterCount++;
  96. }
  97.  
  98. // structure
  99. return statsHolder;
  100. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty