From ed71fb000f98137bec2c181997a219932b88b798 Mon Sep 17 00:00:00 2001 From: TheUltimateOptimist Date: Sun, 28 Jan 2024 00:14:19 +0100 Subject: [PATCH 01/22] defined userinput.h --- src/userinput.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/userinput.h diff --git a/src/userinput.h b/src/userinput.h new file mode 100644 index 0000000..9339d55 --- /dev/null +++ b/src/userinput.h @@ -0,0 +1,13 @@ +#ifndef USERINPUT_H +#define USERINPUT_H +char *getstr(char *message, unsigned long *minLength, unsigned long *maxLength); +short gethd(char *message, short *min, short *max); +int getd(char *message, int *min, int *max); +long getld(char *message, long *min, long *max); +long long getlld(char *message, long long *min, long long *max); +unsigned short gethu(char *message, unsigned short *min, unsigned short *max); +unsigned int getu(char *message, unsigned int *min, unsigned int *max); +unsigned long getul(char *message, unsigned long *min, unsigned long *max); +unsigned long long getull(char *message, unsigned long long *min, unsigned long long *max); +double getlf(char *message, double *min, double *max, double *greaterThan, double *smallerThan); +#endif From 0904ca472ce4cc16e3869368b33eaa919d1a2c11 Mon Sep 17 00:00:00 2001 From: TheUltimateOptimist Date: Sun, 28 Jan 2024 00:30:07 +0100 Subject: [PATCH 02/22] created userinput.c --- src/userinput.c | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/userinput.c diff --git a/src/userinput.c b/src/userinput.c new file mode 100644 index 0000000..863c005 --- /dev/null +++ b/src/userinput.c @@ -0,0 +1 @@ +#include "userinput.h" \ No newline at end of file From daa595a3227ac1c84f87ec8732ac1f081e8b6bea Mon Sep 17 00:00:00 2001 From: TheUltimateOptimist Date: Sun, 28 Jan 2024 00:33:43 +0100 Subject: [PATCH 03/22] implemented trimLeft --- src/userinput.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/userinput.c b/src/userinput.c index 863c005..bd343e9 100644 --- a/src/userinput.c +++ b/src/userinput.c @@ -1 +1,15 @@ -#include "userinput.h" \ No newline at end of file +#include "userinput.h" + +#include +#include + +void trimLeft(char *input) { + size_t length = strlen(input); + int firstIndex = 0; + while (firstIndex < length && isspace(input[firstIndex])) { + firstIndex++; + } + for (int i = 0; i <= length - firstIndex; i++) { + input[i] = input[firstIndex + i]; + } +} \ No newline at end of file From e4fdad7ce366ce2e6dec8adf6177ee18c6b595c4 Mon Sep 17 00:00:00 2001 From: TheUltimateOptimist Date: Sun, 28 Jan 2024 00:34:25 +0100 Subject: [PATCH 04/22] implemented trimRight --- src/userinput.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/userinput.c b/src/userinput.c index bd343e9..e161a63 100644 --- a/src/userinput.c +++ b/src/userinput.c @@ -12,4 +12,13 @@ void trimLeft(char *input) { for (int i = 0; i <= length - firstIndex; i++) { input[i] = input[firstIndex + i]; } +} + +void trimRight(char *input) { + size_t length = strlen(input); + int index = length - 1; + while (index >= 0 && isspace(input[index])) { + input[index] = '\0'; + index--; + } } \ No newline at end of file From eef850ed11fb73f1d69b07a12e2140ab773cc4bd Mon Sep 17 00:00:00 2001 From: TheUltimateOptimist Date: Sun, 28 Jan 2024 00:35:54 +0100 Subject: [PATCH 05/22] implemented readInput --- src/userinput.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/userinput.c b/src/userinput.c index e161a63..8fe6660 100644 --- a/src/userinput.c +++ b/src/userinput.c @@ -2,6 +2,7 @@ #include #include +#include void trimLeft(char *input) { size_t length = strlen(input); @@ -21,4 +22,28 @@ void trimRight(char *input) { input[index] = '\0'; index--; } +} + +char *readInput() { + size_t bufferSize = 100; + char *buffer = malloc(bufferSize*sizeof(char)); + char c; + int index = 0; + do { + c = fgetc(stdin); + if (!(bufferSize > index)) { + char *newBuffer = malloc(2*bufferSize*sizeof(char)); + for (int i = 0; i < bufferSize; i++) { + newBuffer[i] = buffer[i]; + } + bufferSize *= 2; + } + buffer[index] = c; + index++; + } + while(c != '\n' && c != EOF); + buffer[index - 1] = '\0'; + trimLeft(buffer); + trimRight(buffer); + return buffer; } \ No newline at end of file From 239679e77aaf0857b16852d5fa2bbaf8d5aef889 Mon Sep 17 00:00:00 2001 From: TheUltimateOptimist Date: Sun, 28 Jan 2024 00:51:13 +0100 Subject: [PATCH 06/22] implemented getstr --- src/userinput.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/userinput.c b/src/userinput.c index 8fe6660..ec1a8f1 100644 --- a/src/userinput.c +++ b/src/userinput.c @@ -3,6 +3,7 @@ #include #include #include +#include void trimLeft(char *input) { size_t length = strlen(input); @@ -46,4 +47,26 @@ char *readInput() { trimLeft(buffer); trimRight(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; } \ No newline at end of file From a3869ae3a47dfc75add710a9eec1d5b49dc12b53 Mon Sep 17 00:00:00 2001 From: TheUltimateOptimist Date: Sun, 28 Jan 2024 00:57:29 +0100 Subject: [PATCH 07/22] implemented printlf --- project.yml | 2 +- src/userinput.c | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/project.yml b/project.yml index e253248..a54e1f4 100644 --- a/project.yml +++ b/project.yml @@ -88,7 +88,7 @@ :placement: :end :flag: "-l${1}" :path_flag: "-L ${1}" - :system: [] # for example, you might list 'm' to grab the math library + :system: [m] # for example, you might list 'm' to grab the math library :test: [] :release: [] diff --git a/src/userinput.c b/src/userinput.c index ec1a8f1..9792e50 100644 --- a/src/userinput.c +++ b/src/userinput.c @@ -4,6 +4,7 @@ #include #include #include +#include void trimLeft(char *input) { size_t length = strlen(input); @@ -69,4 +70,13 @@ char *getstr(char *message, unsigned long *minLength, unsigned long *maxLength) result = readInput(); } return result; +} + +void printlf(long double value) { + if (roundl(value) == value) { + printf("%.0Lf", value); + } + else { + printf("%Lf", value); + } } \ No newline at end of file From 51b00fb57a1aaf402817038b2fe582d26b4c299b Mon Sep 17 00:00:00 2001 From: TheUltimateOptimist Date: Sun, 28 Jan 2024 01:00:13 +0100 Subject: [PATCH 08/22] implemented getNumber --- src/userinput.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/src/userinput.c b/src/userinput.c index 9792e50..554b296 100644 --- a/src/userinput.c +++ b/src/userinput.c @@ -5,6 +5,7 @@ #include #include #include +#include void trimLeft(char *input) { size_t length = strlen(input); @@ -79,4 +80,74 @@ void printlf(long double value) { else { printf("%Lf", value); } +} + +long double getNumber(char *message, long double *min, long double *max, long double *greaterThan, long double *smallerThan, long double leftBorder, long double rightBorder) { + while (1) { + char *input = getstr(message, NULL, NULL); + if (strlen(input) == 0) { + printf("%s\n", "Fehlende Eingabe!"); + fflush(stdout); + free(input); + continue; + } + char *endptr; + long double number = strtold(input, &endptr); + if (strlen(endptr) > 0) { + printf("%s\n", "Ungueltige Eingabe! Gib eine gueltige Zahl ein."); + fflush(stdout); + free(input); + continue; + } + free(input); + bool isValid = true; + if (min != NULL && number < *min) { + isValid = false; + } + if (max != NULL && number > *max) { + isValid = false; + } + if (greaterThan != NULL && !(number > *greaterThan)) { + isValid = false; + } + if (smallerThan != NULL && !(number < *smallerThan)) { + isValid = false; + } + if (number < leftBorder) { + isValid = false; + } + if (number > rightBorder) { + isValid = false; + } + if (isValid) { + return number; + } + printf("Ungueltige Eingabe! Fuer die eingegebene Zahl muss gelten:"); + if (min != NULL) { + printf(" >="); + printlf(*min); + } + if (max != NULL) { + printf(" <="); + printlf(*max); + } + if (greaterThan != NULL) { + printf(" >"); + printlf(*greaterThan); + } + if (smallerThan != NULL) { + printf(" <"); + printlf(*smallerThan); + } + if (min == NULL && greaterThan == NULL) { + printf(" >="); + printlf(leftBorder); + } + if (max == NULL && smallerThan == NULL) { + printf(" <="); + printlf(rightBorder); + } + printf("\n"); + fflush(stdout); + } } \ No newline at end of file From d2a2ce7ab060866e397480c57e147aafe8f9704c Mon Sep 17 00:00:00 2001 From: TheUltimateOptimist Date: Sun, 28 Jan 2024 01:02:15 +0100 Subject: [PATCH 09/22] implemented LD macro --- src/userinput.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/userinput.c b/src/userinput.c index 554b296..9a3e85f 100644 --- a/src/userinput.c +++ b/src/userinput.c @@ -7,6 +7,15 @@ #include #include +#define LD(name)\ + long double name##ldvalue;\ + long double *name##ld = NULL;\ + if (name != NULL) {\ + name##ldvalue = *name;\ + name##ld = &name##ldvalue;\ + } + + void trimLeft(char *input) { size_t length = strlen(input); int firstIndex = 0; From d378fa1a31459407b4ebf8fb3eba2d39f33496db Mon Sep 17 00:00:00 2001 From: TheUltimateOptimist Date: Sun, 28 Jan 2024 01:03:10 +0100 Subject: [PATCH 10/22] implemented gethd --- src/userinput.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/userinput.c b/src/userinput.c index 9a3e85f..24946dc 100644 --- a/src/userinput.c +++ b/src/userinput.c @@ -6,6 +6,7 @@ #include #include #include +#include #define LD(name)\ long double name##ldvalue;\ @@ -159,4 +160,10 @@ long double getNumber(char *message, long double *min, long double *max, long do printf("\n"); fflush(stdout); } +} + +short gethd(char *message, short *min, short *max) { + LD(min) + LD(max) + return getNumber(message, minld, maxld, NULL, NULL, SHRT_MIN, SHRT_MAX); } \ No newline at end of file From 2729c4b9d2e27fdcbffffd4361bfe800c6dc1a6e Mon Sep 17 00:00:00 2001 From: TheUltimateOptimist Date: Sun, 28 Jan 2024 01:03:39 +0100 Subject: [PATCH 11/22] implemented getd --- src/userinput.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/userinput.c b/src/userinput.c index 24946dc..20372f8 100644 --- a/src/userinput.c +++ b/src/userinput.c @@ -166,4 +166,10 @@ short gethd(char *message, short *min, short *max) { LD(min) LD(max) return getNumber(message, minld, maxld, NULL, NULL, SHRT_MIN, SHRT_MAX); +} + +int getd(char *message, int *min, int *max) { + LD(min) + LD(max) + return getNumber(message, minld, maxld, NULL, NULL, INT_MIN, INT_MAX); } \ No newline at end of file From 3a00cb92d137d4ba1b1be773c4abe277812c644c Mon Sep 17 00:00:00 2001 From: TheUltimateOptimist Date: Sun, 28 Jan 2024 01:03:58 +0100 Subject: [PATCH 12/22] implemented getld --- src/userinput.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/userinput.c b/src/userinput.c index 20372f8..bff0250 100644 --- a/src/userinput.c +++ b/src/userinput.c @@ -172,4 +172,10 @@ int getd(char *message, int *min, int *max) { LD(min) LD(max) return getNumber(message, minld, maxld, NULL, NULL, INT_MIN, INT_MAX); +} + +long getld(char *message, long *min, long *max) { + LD(min) + LD(max) + return getNumber(message, minld, maxld, NULL, NULL, LONG_MIN, LONG_MAX); } \ No newline at end of file From 501bedbf8734121395e61054363e026599c9d11e Mon Sep 17 00:00:00 2001 From: TheUltimateOptimist Date: Sun, 28 Jan 2024 01:04:21 +0100 Subject: [PATCH 13/22] implemented getlld --- src/userinput.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/userinput.c b/src/userinput.c index bff0250..ef403d1 100644 --- a/src/userinput.c +++ b/src/userinput.c @@ -178,4 +178,10 @@ long getld(char *message, long *min, long *max) { LD(min) LD(max) return getNumber(message, minld, maxld, NULL, NULL, LONG_MIN, LONG_MAX); +} + +long long getlld(char *message, long long *min, long long *max) { + LD(min) + LD(max) + return getNumber(message, minld, maxld, NULL, NULL, LLONG_MIN, LLONG_MAX); } \ No newline at end of file From 80aeacef8b7ba279da33e444fe5e134a82d9c4eb Mon Sep 17 00:00:00 2001 From: TheUltimateOptimist Date: Sun, 28 Jan 2024 01:04:38 +0100 Subject: [PATCH 14/22] implemented gethu --- src/userinput.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/userinput.c b/src/userinput.c index ef403d1..755e748 100644 --- a/src/userinput.c +++ b/src/userinput.c @@ -184,4 +184,10 @@ long long getlld(char *message, long long *min, long long *max) { LD(min) LD(max) return getNumber(message, minld, maxld, NULL, NULL, LLONG_MIN, LLONG_MAX); +} + +unsigned short gethu(char *message, unsigned short *min, unsigned short *max) { + LD(min) + LD(max) + return getNumber(message, minld, maxld, NULL, NULL, 0, USHRT_MAX); } \ No newline at end of file From f7166d349cf053f7488b049229caa43b125dde18 Mon Sep 17 00:00:00 2001 From: TheUltimateOptimist Date: Sun, 28 Jan 2024 01:05:02 +0100 Subject: [PATCH 15/22] implemented getu --- src/userinput.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/userinput.c b/src/userinput.c index 755e748..7f8f890 100644 --- a/src/userinput.c +++ b/src/userinput.c @@ -190,4 +190,10 @@ unsigned short gethu(char *message, unsigned short *min, unsigned short *max) { LD(min) LD(max) return getNumber(message, minld, maxld, NULL, NULL, 0, USHRT_MAX); +} + +unsigned int getu(char *message, unsigned int *min, unsigned int *max) { + LD(min) + LD(max) + return getNumber(message, minld, maxld, NULL, NULL, 0, UINT_MAX); } \ No newline at end of file From 159fe0a0179f984f110cd5e2857fb9743771b789 Mon Sep 17 00:00:00 2001 From: TheUltimateOptimist Date: Sun, 28 Jan 2024 01:05:20 +0100 Subject: [PATCH 16/22] implemented getul --- src/userinput.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/userinput.c b/src/userinput.c index 7f8f890..35827f1 100644 --- a/src/userinput.c +++ b/src/userinput.c @@ -196,4 +196,10 @@ unsigned int getu(char *message, unsigned int *min, unsigned int *max) { LD(min) LD(max) return getNumber(message, minld, maxld, NULL, NULL, 0, UINT_MAX); +} + +unsigned long getul(char *message, unsigned long *min, unsigned long *max) { + LD(min) + LD(max) + return getNumber(message, minld, maxld, NULL, NULL, 0, ULONG_MAX); } \ No newline at end of file From 30cd3152c8278ce6bd530a339e48f5bfeca5b874 Mon Sep 17 00:00:00 2001 From: TheUltimateOptimist Date: Sun, 28 Jan 2024 01:10:49 +0100 Subject: [PATCH 17/22] implemented getull --- src/userinput.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/userinput.c b/src/userinput.c index 35827f1..f57d0b0 100644 --- a/src/userinput.c +++ b/src/userinput.c @@ -202,4 +202,10 @@ unsigned long getul(char *message, unsigned long *min, unsigned long *max) { LD(min) LD(max) return getNumber(message, minld, maxld, NULL, NULL, 0, ULONG_MAX); +} + +unsigned long long getull(char *message, unsigned long long *min, unsigned long long *max) { + LD(min) + LD(max) + return getNumber(message, minld, maxld, NULL, NULL, 0, ULLONG_MAX); } \ No newline at end of file From e2fb2c4835fd9a6efe42b956c1a262289adbc50e Mon Sep 17 00:00:00 2001 From: TheUltimateOptimist Date: Sun, 28 Jan 2024 01:11:32 +0100 Subject: [PATCH 18/22] implemented getlf --- src/userinput.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/userinput.c b/src/userinput.c index f57d0b0..4b641fa 100644 --- a/src/userinput.c +++ b/src/userinput.c @@ -7,6 +7,7 @@ #include #include #include +#include #define LD(name)\ long double name##ldvalue;\ @@ -208,4 +209,12 @@ unsigned long long getull(char *message, unsigned long long *min, unsigned long LD(min) LD(max) return getNumber(message, minld, maxld, NULL, NULL, 0, ULLONG_MAX); +} + +double getlf(char *message, double *min, double *max, double *greaterThan, double *smallerThan) { + LD(min) + LD(max) + LD(greaterThan) + LD(smallerThan) + return getNumber(message, minld, maxld, greaterThanld, smallerThanld, -DBL_MAX, DBL_MAX); } \ No newline at end of file From 0e9044cce9a67e9c197c680df44253edc5a0fab8 Mon Sep 17 00:00:00 2001 From: TheUltimateOptimist Date: Sun, 28 Jan 2024 01:18:22 +0100 Subject: [PATCH 19/22] refactoring: renamed getul to getlu --- src/userinput.c | 2 +- src/userinput.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/userinput.c b/src/userinput.c index 4b641fa..089a31f 100644 --- a/src/userinput.c +++ b/src/userinput.c @@ -199,7 +199,7 @@ unsigned int getu(char *message, unsigned int *min, unsigned int *max) { return getNumber(message, minld, maxld, NULL, NULL, 0, UINT_MAX); } -unsigned long getul(char *message, unsigned long *min, unsigned long *max) { +unsigned long getlu(char *message, unsigned long *min, unsigned long *max) { LD(min) LD(max) return getNumber(message, minld, maxld, NULL, NULL, 0, ULONG_MAX); diff --git a/src/userinput.h b/src/userinput.h index 9339d55..e8105d5 100644 --- a/src/userinput.h +++ b/src/userinput.h @@ -7,7 +7,7 @@ long getld(char *message, long *min, long *max); long long getlld(char *message, long long *min, long long *max); unsigned short gethu(char *message, unsigned short *min, unsigned short *max); unsigned int getu(char *message, unsigned int *min, unsigned int *max); -unsigned long getul(char *message, unsigned long *min, unsigned long *max); +unsigned long getlu(char *message, unsigned long *min, unsigned long *max); unsigned long long getull(char *message, unsigned long long *min, unsigned long long *max); double getlf(char *message, double *min, double *max, double *greaterThan, double *smallerThan); #endif From e8895cee2ac13068e88b282482fe2be5c7c03d1e Mon Sep 17 00:00:00 2001 From: TheUltimateOptimist Date: Sun, 28 Jan 2024 01:19:04 +0100 Subject: [PATCH 20/22] refactoring: renamed getull to getllu --- src/userinput.c | 2 +- src/userinput.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/userinput.c b/src/userinput.c index 089a31f..a3729d3 100644 --- a/src/userinput.c +++ b/src/userinput.c @@ -205,7 +205,7 @@ unsigned long getlu(char *message, unsigned long *min, unsigned long *max) { return getNumber(message, minld, maxld, NULL, NULL, 0, ULONG_MAX); } -unsigned long long getull(char *message, unsigned long long *min, unsigned long long *max) { +unsigned long long getllu(char *message, unsigned long long *min, unsigned long long *max) { LD(min) LD(max) return getNumber(message, minld, maxld, NULL, NULL, 0, ULLONG_MAX); diff --git a/src/userinput.h b/src/userinput.h index e8105d5..9afa84a 100644 --- a/src/userinput.h +++ b/src/userinput.h @@ -8,6 +8,6 @@ long long getlld(char *message, long long *min, long long *max); unsigned short gethu(char *message, unsigned short *min, unsigned short *max); unsigned int getu(char *message, unsigned int *min, unsigned int *max); unsigned long getlu(char *message, unsigned long *min, unsigned long *max); -unsigned long long getull(char *message, unsigned long long *min, unsigned long long *max); +unsigned long long getllu(char *message, unsigned long long *min, unsigned long long *max); double getlf(char *message, double *min, double *max, double *greaterThan, double *smallerThan); #endif From f01127845b764655d7126668c974714088d886ea Mon Sep 17 00:00:00 2001 From: TheUltimateOptimist Date: Sun, 28 Jan 2024 01:46:56 +0100 Subject: [PATCH 21/22] refactoring: renamed getstr to gets --- src/userinput.c | 4 ++-- src/userinput.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/userinput.c b/src/userinput.c index a3729d3..cdf03c6 100644 --- a/src/userinput.c +++ b/src/userinput.c @@ -62,7 +62,7 @@ char *readInput() { return buffer; } -char *getstr(char *message, unsigned long *minLength, unsigned long *maxLength) { +char *gets(char *message, unsigned long *minLength, unsigned long *maxLength) { printf("%s", message); fflush(stdout); char *result = readInput(); @@ -95,7 +95,7 @@ void printlf(long double value) { long double getNumber(char *message, long double *min, long double *max, long double *greaterThan, long double *smallerThan, long double leftBorder, long double rightBorder) { while (1) { - char *input = getstr(message, NULL, NULL); + char *input = gets(message, NULL, NULL); if (strlen(input) == 0) { printf("%s\n", "Fehlende Eingabe!"); fflush(stdout); diff --git a/src/userinput.h b/src/userinput.h index 9afa84a..a693f60 100644 --- a/src/userinput.h +++ b/src/userinput.h @@ -1,6 +1,6 @@ #ifndef USERINPUT_H #define USERINPUT_H -char *getstr(char *message, unsigned long *minLength, unsigned long *maxLength); +char *gets(char *message, unsigned long *minLength, unsigned long *maxLength); short gethd(char *message, short *min, short *max); int getd(char *message, int *min, int *max); long getld(char *message, long *min, long *max); From 791155b0203a14011ddfb375f4c95bbe4a48cffe Mon Sep 17 00:00:00 2001 From: TheUltimateOptimist Date: Sun, 28 Jan 2024 02:23:03 +0100 Subject: [PATCH 22/22] documentation: documented functions from userinput.h --- src/userinput.h | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/userinput.h b/src/userinput.h index a693f60..9646ad9 100644 --- a/src/userinput.h +++ b/src/userinput.h @@ -1,13 +1,79 @@ #ifndef USERINPUT_H #define USERINPUT_H + +/// userinput.h provides functions for retrieving user input. +/// The functions are named get + placeholder used by printf for the given datatype. +/// string -> gets +/// short ind -> gethd +/// int -> getd +/// long -> getld +/// long long -> getlld +/// unsigned short -> gethu +/// unsigned int -> getu +/// unsigned long -> getlu +/// unsigned long long -> getllu +/// double -> getlf +/// The provided functions handle validating the user input and ask again for input +/// with the given message until it is valid. + +/// Using the given message gets asks the user to enter a string repeatedly +/// until its length is between minLength and maxLength (both inclusive). +/// The obtained string is then returned. +/// If you don't want to enforce a minLength or a maxLength you can assign it to NULL. char *gets(char *message, unsigned long *minLength, unsigned long *maxLength); + +/// Using the given message gethd asks the user to enter a short repeatedly +/// until it is in the valid range for a short and between min and max (both inclusive) if provided. +/// The obtained short is then returned. +/// If you don't want to enforce a min or max you can assign it to NULL. short gethd(char *message, short *min, short *max); + +/// Using the given message getd asks the user to enter an int repeatedly +/// until it is in the valid range for an int and between min and max (both inclusive) if provided. +/// The obtained int is then returned. +/// If you don't want to enforce a min or max you can assign it to NULL. int getd(char *message, int *min, int *max); + +/// Using the given message getld asks the user to enter a long repeatedly +/// until it is in the valid range for a long and between min and max (both inclusive) if provided. +/// The obtained long is then returned. +/// If you don't want to enforce a min or max you can assign it to NULL. long getld(char *message, long *min, long *max); + +/// Using the given message getlld asks the user to enter a long long repeatedly +/// until it is in the valid range for a long long and between min and max (both inclusive) if provided. +/// The obtained long is then returned. +/// If you don't want to enforce a min or max you can assign it to NULL. long long getlld(char *message, long long *min, long long *max); + +/// Using the given message gethu asks the user to enter an unsigned short repeatedly +/// until it is in the valid range for an unsigned short and between min and max (both inclusive) if provided. +/// The obtained unsigned short is then returned. +/// If you don't want to enforce a min or max you can assign it to NULL. unsigned short gethu(char *message, unsigned short *min, unsigned short *max); + +/// Using the given message getu asks the user to enter an unsigned int repeatedly +/// until it is in the valid range for an unsigned int and between min and max (both inclusive) if provided. +/// The obtained unsigned int is then returned. +/// If you don't want to enforce a min or max you can assign it to NULL. unsigned int getu(char *message, unsigned int *min, unsigned int *max); + +/// Using the given message getlu asks the user to enter an unsigned long repeatedly +/// until it is in the valid range for an unsigned long and between min and max (both inclusive) if provided. +/// The obtained unsigned long is then returned. +/// If you don't want to enforce a min or max you can assign it to NULL. unsigned long getlu(char *message, unsigned long *min, unsigned long *max); + +/// Using the given message getllu asks the user to enter an unsigned long long repeatedly +/// until it is in the valid range for an unsigned long long and between min and max (both inclusive) if provided. +/// The obtained unsigned long long is then returned. +/// If you don't want to enforce a min or max you can assign it to NULL. unsigned long long getllu(char *message, unsigned long long *min, unsigned long long *max); + +/// Using the given message getlf asks the user to enter a double repeatedly +/// until it is in the valid range for a double, between min and max (both inclusive), +/// greater than the given greaterThan and smaller than the given smallerThan. +/// The obtained double is then returned. +/// If you don't want to enforce a min, max, greaterThan or smallerThan you can assign them to NULL. double getlf(char *message, double *min, double *max, double *greaterThan, double *smallerThan); #endif