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.

84 lines
1.5 KiB

/***********************
* Stringstats
*
* Rainer Hihn
*/
#include <stdio.h>
#define LENGTH 64
/*
* Funktion deklarieren
*/
int stringstats(char[], char *, char *);
int stringstats(char sString[], char* cGroesster, char* cKleinster)
{
/**
* Variablendeklaration
*/
int iLength = 0;
int i = 0;
*cKleinster = sString[0];
*cGroesster = sString[0];
while(sString[iLength] != '\0')
{
iLength++;
}
for(i = 0; i <= iLength-1; i++)
{
if(sString[i] < *cKleinster)
{
*cKleinster = sString[i];
}
if(sString[i] > *cGroesster)
{
*cGroesster = sString[i];
}
}
return iLength;
}
int main(void)
{
/**
* Variablendeklaration
*/
char cString[LENGTH] = {0};
int iLength = 0;
char cGroesster = 0;
char cKleinster = 0;
while(1)
{
/**
* Benutzereingabe String
*/
printf("Bitte einen String eingeben ('q' fuer Beenden) \n");
scanf("%62s", &cString);
/**
* Abbruchbedingung pruefen
*/
if(cString[0] == 'q' && cString[1] == '\0')
{
break;
}
/**
* Funktion stringstats aufrufen
*/
iLength = stringstats(cString, &cGroesster, &cKleinster);
printf("Laenge: %i \n", iLength);
printf("Kleinster Buchstabe: %c \n", cKleinster);
printf("Groesster Buchstabe: %c \n\n", cGroesster);
}
return 0;
}