fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. struct stringStats
  5. {
  6. int stringLength; //number of total characters in the string
  7. int upperCaseCount; //number of upper case characters
  8. int lowerCaseCount; //number of lower case characters
  9. int numDigits; //number of digits
  10. int numBlankSpaces; //number of blank spaces
  11. int nonAlphaChars; //number of non-alphanumeric characters
  12. int numVowels; //number of vowels (the letters a, e, i, o, u)   ... accept upper and lower case
  13. int numNonVowels; //number of non-vowels ... accept upper and lower case
  14. int numSpecChars; //number of special characters
  15. int numPrintableChars; //all printable characters that are neither alphanumeric nor a space. For example ‘@’, ‘$’, etc.
  16. int numHexaDecDigits; //number of hexadecimal "digits" -  0 through 9 ... and the letters A - F  ... accept upper and lower case
  17. int numOctalDigits; //number of octal "digits" - 0 to 7
  18. int numBinaryDigits; //number of binary "digits" - 0 or 1
  19. int numPunctChars; //number of punctuator characters
  20. int numControlChars; //number of control characters
  21. };
  22.  
  23. //**************************************************************
  24. // Function: stringStats
  25. //
  26. // Purpose: Determine string stats
  27. //
  28. // Parameters:
  29. //
  30. // theString - string/word that getting stats on
  31. //
  32. // Returns: structure wth string stats
  33. //
  34. //**************************************************************
  35.  
  36. // function prototype to get started, or better, use pointers */
  37. struct stringStats getStringStats (char theString[]){
  38.  
  39. //Declare a variable of type stringStats
  40. struct stringStats stringStats1;
  41.  
  42. int numChars = strlen(theString); //calculate the number of characters
  43. stringStats1.stringLength=numChars;
  44.  
  45. int numUpperCase=0; //initialize to 0 the number of upper case characters
  46. int numLowerCase=0; //initialize to 0 the number of lower case characters
  47.  
  48. for (int i = 0; i < numChars; i++){ //looping through the number of characters in the string
  49. if (theString[i] >= 'A' && theString[i] <= 'Z'){
  50. /*numUpperCase++;*/ //looking for upper case characters and if found, increment the variable that stored the number of uppercase characters by 1
  51. }
  52. else if (theString[i] >= 'a' && theString[i] <= 'z'){
  53. numLowerCase++; //looking for lower case characters and if found, increment the variable that stored the number of uppercase characters by 1
  54. }
  55. };
  56.  
  57. stringStats1.upperCaseCount=numUpperCase;
  58. stringStats1.upperCaseCount=numLowerCase;
  59.  
  60. return stringStats1;
  61.  
  62. };
  63. int main() {
  64.  
  65. // set up structure to store totals and initialize all to zero
  66. struct stringStats retStringStats = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  67.  
  68. retStringStats = getStringStats("by");
  69. printf("Number of characters: %i\n", retStringStats.stringLength);
  70. printf("Number of upper case letters: %i\n", retStringStats.upperCaseCount);
  71. printf("Number of lower case letters: %i\n", retStringStats.lowerCaseCount);
  72. return 0;
  73. };
Success #stdin #stdout 0s 5292KB
stdin
Standard input is empty
stdout
Number of characters: 2
Number of upper case letters: 2
Number of lower case letters: 16524902