fork download
  1. // Assignment Question 5 Final Exam
  2. //
  3. // Name: <Tasos Paloukos>
  4. //
  5. // Class: C Programming, <Fall 2024>
  6. //
  7. // Date: <December 11, 2024>
  8.  
  9. #include <stdio.h>
  10. #include <ctype.h>
  11.  
  12. // Define the structure
  13. struct stringStats {
  14. int stringLength;
  15. int upperCaseCount;
  16. int lowerCaseCount;
  17. int digitCount;
  18. int spaceCount;
  19. int specialCharCount;
  20. };
  21.  
  22. // Function prototype
  23. struct stringStats getStringStats(char theString[]);
  24.  
  25. // Function definition
  26. struct stringStats getStringStats(char theString[]) {
  27. struct stringStats stats = {0, 0, 0, 0, 0, 0}; // Initialize all members to 0
  28. int i = 0;
  29.  
  30. while (theString[i] != '\0') {
  31. stats.stringLength++;
  32. if (isupper(theString[i])) {
  33. stats.upperCaseCount++;
  34. } else if (islower(theString[i])) {
  35. stats.lowerCaseCount++;
  36. } else if (isdigit(theString[i])) {
  37. stats.digitCount++;
  38. } else if (isspace(theString[i])) {
  39. stats.spaceCount++;
  40. } else {
  41. stats.specialCharCount++;
  42. }
  43. i++;
  44. }
  45. return stats;
  46. }
  47.  
  48. // Main function
  49. int main() {
  50. char inputString[] = "Hello World! 123";
  51. struct stringStats result = getStringStats(inputString);
  52.  
  53. printf("String Length: %d\n", result.stringLength);
  54. printf("Uppercase Letters: %d\n", result.upperCaseCount);
  55. printf("Lowercase Letters: %d\n", result.lowerCaseCount);
  56. printf("Digits: %d\n", result.digitCount);
  57. printf("Spaces: %d\n", result.spaceCount);
  58. printf("Special Characters: %d\n", result.specialCharCount);
  59.  
  60. return 0;
  61. }
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
String Length: 16
Uppercase Letters: 2
Lowercase Letters: 8
Digits: 3
Spaces: 2
Special Characters: 1