|
@ -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); |
|
@ -47,3 +48,25 @@ char *readInput() { |
|
|
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; |
|
|
|
|
|
} |