You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
1.5 KiB

  1. /***********************
  2. * Stringstats
  3. *
  4. * Rainer Hihn
  5. */
  6. #include <stdio.h>
  7. #define LENGTH 64
  8. /*
  9. * Funktion deklarieren
  10. */
  11. int stringstats(char[], char *, char *);
  12. int stringstats(char sString[], char* cGroesster, char* cKleinster)
  13. {
  14. /**
  15. * Variablendeklaration
  16. */
  17. int iLength = 0;
  18. int i = 0;
  19. *cKleinster = sString[0];
  20. *cGroesster = sString[0];
  21. while(sString[iLength] != '\0')
  22. {
  23. iLength++;
  24. }
  25. for(i = 0; i <= iLength-1; i++)
  26. {
  27. if(sString[i] < *cKleinster)
  28. {
  29. *cKleinster = sString[i];
  30. }
  31. if(sString[i] > *cGroesster)
  32. {
  33. *cGroesster = sString[i];
  34. }
  35. }
  36. return iLength;
  37. }
  38. int main(void)
  39. {
  40. /**
  41. * Variablendeklaration
  42. */
  43. char cString[LENGTH] = {0};
  44. int iLength = 0;
  45. char cGroesster = 0;
  46. char cKleinster = 0;
  47. while(1)
  48. {
  49. /**
  50. * Benutzereingabe String
  51. */
  52. printf("Bitte einen String eingeben ('q' fuer Beenden) \n");
  53. scanf("%62s", &cString);
  54. /**
  55. * Abbruchbedingung pruefen
  56. */
  57. if(cString[0] == 'q' && cString[1] == '\0')
  58. {
  59. break;
  60. }
  61. /**
  62. * Funktion stringstats aufrufen
  63. */
  64. iLength = stringstats(cString, &cGroesster, &cKleinster);
  65. printf("Laenge: %i \n", iLength);
  66. printf("Kleinster Buchstabe: %c \n", cKleinster);
  67. printf("Groesster Buchstabe: %c \n\n", cGroesster);
  68. }
  69. return 0;
  70. }