|
@ -3,6 +3,7 @@ |
|
|
#include <ctype.h> |
|
|
#include <ctype.h> |
|
|
#include <stdio.h> |
|
|
#include <stdio.h> |
|
|
#include <stdlib.h> |
|
|
#include <stdlib.h> |
|
|
|
|
|
#include <string.h> |
|
|
|
|
|
|
|
|
void trimLeft(char *input) { |
|
|
void trimLeft(char *input) { |
|
|
size_t length = strlen(input); |
|
|
size_t length = strlen(input); |
|
@ -46,4 +47,26 @@ char *readInput() { |
|
|
trimLeft(buffer); |
|
|
trimLeft(buffer); |
|
|
trimRight(buffer); |
|
|
trimRight(buffer); |
|
|
return buffer; |
|
|
return buffer; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
char *getstr(char *message, unsigned long *minLength, unsigned long *maxLength) { |
|
|
|
|
|
printf("%s", message); |
|
|
|
|
|
fflush(stdout); |
|
|
|
|
|
char *result = readInput(); |
|
|
|
|
|
while (minLength != NULL && strlen(result) < *minLength || maxLength != NULL && strlen(result) > *maxLength) { |
|
|
|
|
|
printf("%s", "Ungueltige Eingabe! "); |
|
|
|
|
|
if (minLength != NULL && maxLength == NULL) { |
|
|
|
|
|
printf("Die Eingabe muss mind. %lu Zeichen lang sein.\n", *minLength); |
|
|
|
|
|
} |
|
|
|
|
|
else if (maxLength != NULL && minLength == NULL) { |
|
|
|
|
|
printf("Die Eingabe darf maximal %lu Zeichen lang sein.\n", *maxLength); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
printf("Die Eingabe muss %lu bis %lu Zeichen lang sein.\n", *minLength, *maxLength); |
|
|
|
|
|
} |
|
|
|
|
|
printf("%s", message); |
|
|
|
|
|
fflush(stdout); |
|
|
|
|
|
result = readInput(); |
|
|
|
|
|
} |
|
|
|
|
|
return result; |
|
|
} |
|
|
} |