From 089e91af430db23b83b9bb7e0040840d341eaf5a Mon Sep 17 00:00:00 2001 From: Laurin Date: Tue, 6 Feb 2024 13:39:58 +0100 Subject: [PATCH 1/5] Implemented interface for main program for conversion of numbers --- src/conversionOfNumbers/main.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/conversionOfNumbers/main.c diff --git a/src/conversionOfNumbers/main.c b/src/conversionOfNumbers/main.c new file mode 100644 index 0000000..375e414 --- /dev/null +++ b/src/conversionOfNumbers/main.c @@ -0,0 +1,30 @@ +#include "conversionOfNumbers.h" +#include "../userinput.h" +#include + +int main(){ + int min = 0; + int max = 2; + int InputSys; + while(InputSys != 3){ + + printf("\nWaehle Zahlensystem:\n" + "\n<0> Binaer System\n" + "<1> Hexadezimal System\n" + "<2> Beenden\n"); + InputSys = usergetd("\nEingabe: ", &min, &max); + if(InputSys == 2) break; + int InputProg; + + while(InputProg != 3){ + + printf("\nZu oder von einer Dezimalzahl konvertieren?\n" + "\n<0> Zu\n" + "<1> Von\n" + "<2> Hauptmenue\n"); + InputProg = usergetd("\nEingabe: ", &min, &max); + if(InputProg == 2) break; + } + } + return 0; +} \ No newline at end of file From d31e8c54639c954fbdcaf4155f13f8ad2d082215 Mon Sep 17 00:00:00 2001 From: Laurin Date: Tue, 6 Feb 2024 14:02:28 +0100 Subject: [PATCH 2/5] Implemented interface and functions to convert from or into binary system in main program --- src/conversionOfNumbers/main.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/conversionOfNumbers/main.c b/src/conversionOfNumbers/main.c index 375e414..fe9d7ec 100644 --- a/src/conversionOfNumbers/main.c +++ b/src/conversionOfNumbers/main.c @@ -24,6 +24,18 @@ int main(){ "<2> Hauptmenue\n"); InputProg = usergetd("\nEingabe: ", &min, &max); if(InputProg == 2) break; + if(InputSys == 0){ + if(InputProg == 0){ + char* toConvert = usergets("\nGeben Sie eine Zeichenkette von 0 und 1 ein: ", NULL, NULL); + int result = convertBinaryStrToInt(toConvert); + printf("\nAusgabe (in Dezimal): %d\n", result); + } + if(InputProg == 1){ + int toConvert = usergetd("\nGeben Sie eine Ganzzahl ein: ", NULL, NULL); + char* result = convertIntToBinaryStr(toConvert); + printf("\nAusgabe (in Binaer): %s\n", result); + } + } } } return 0; From 2157c6a2f47bb99d4431735ccf538b9c3cd3da52 Mon Sep 17 00:00:00 2001 From: Laurin Date: Tue, 6 Feb 2024 14:40:02 +0100 Subject: [PATCH 3/5] Implemented interface and functions to convert from or into hexadecimal system in main program --- src/conversionOfNumbers/main.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/conversionOfNumbers/main.c b/src/conversionOfNumbers/main.c index fe9d7ec..c2679ca 100644 --- a/src/conversionOfNumbers/main.c +++ b/src/conversionOfNumbers/main.c @@ -36,6 +36,19 @@ int main(){ printf("\nAusgabe (in Binaer): %s\n", result); } } + if(InputSys == 1){ + if(InputProg == 0){ + char* toConvert = usergets("\nGeben Sie eine Zeichenkette im Hexadezimal-Format ein: ", NULL, NULL); + int result = convertHexStrToInt(toConvert); + printf("\nAusgabe (in Dezimal): %d\n", result); + } + if(InputProg == 1){ + int rangeMin = 0; + int toConvert = usergetd("\nGeben Sie eine positive Ganzzahl ein: ", &rangeMin, NULL); + char* result = convertIntToHex(toConvert); + printf("\nAusgabe (in Hex): %s\n", result); + } + } } } return 0; From 3a704ca670d12400482148da907b191cf518eab4 Mon Sep 17 00:00:00 2001 From: Laurin Date: Tue, 6 Feb 2024 14:43:07 +0100 Subject: [PATCH 4/5] refactoring: freed allocated memory of result strings in main program --- src/conversionOfNumbers/main.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/conversionOfNumbers/main.c b/src/conversionOfNumbers/main.c index c2679ca..b6b5151 100644 --- a/src/conversionOfNumbers/main.c +++ b/src/conversionOfNumbers/main.c @@ -1,6 +1,7 @@ #include "conversionOfNumbers.h" #include "../userinput.h" #include +#include int main(){ int min = 0; @@ -34,6 +35,7 @@ int main(){ int toConvert = usergetd("\nGeben Sie eine Ganzzahl ein: ", NULL, NULL); char* result = convertIntToBinaryStr(toConvert); printf("\nAusgabe (in Binaer): %s\n", result); + free(result); } } if(InputSys == 1){ @@ -47,6 +49,7 @@ int main(){ int toConvert = usergetd("\nGeben Sie eine positive Ganzzahl ein: ", &rangeMin, NULL); char* result = convertIntToHex(toConvert); printf("\nAusgabe (in Hex): %s\n", result); + free(result); } } } From dd0176d5dc7d01c6e8005d1eacd4d6aa6141ab9a Mon Sep 17 00:00:00 2001 From: Laurin Date: Tue, 6 Feb 2024 15:05:29 +0100 Subject: [PATCH 5/5] refactoring: changed variable names to be more specific --- src/conversionOfNumbers/main.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/conversionOfNumbers/main.c b/src/conversionOfNumbers/main.c index b6b5151..fe11889 100644 --- a/src/conversionOfNumbers/main.c +++ b/src/conversionOfNumbers/main.c @@ -4,47 +4,47 @@ #include int main(){ - int min = 0; - int max = 2; - int InputSys; - while(InputSys != 3){ + int minInput = 0; + int maxInput = 2; + int InputMainMenu; + while(InputMainMenu != 3){ printf("\nWaehle Zahlensystem:\n" "\n<0> Binaer System\n" "<1> Hexadezimal System\n" "<2> Beenden\n"); - InputSys = usergetd("\nEingabe: ", &min, &max); - if(InputSys == 2) break; - int InputProg; + InputMainMenu = usergetd("\nEingabe: ", &minInput, &maxInput); + if(InputMainMenu == 2) break; + int InputOptionsMenu; - while(InputProg != 3){ + while(InputOptionsMenu != 3){ printf("\nZu oder von einer Dezimalzahl konvertieren?\n" "\n<0> Zu\n" "<1> Von\n" "<2> Hauptmenue\n"); - InputProg = usergetd("\nEingabe: ", &min, &max); - if(InputProg == 2) break; - if(InputSys == 0){ - if(InputProg == 0){ + InputOptionsMenu = usergetd("\nEingabe: ", &minInput, &maxInput); + if(InputOptionsMenu == 2) break; + if(InputMainMenu == 0){ + if(InputOptionsMenu == 0){ char* toConvert = usergets("\nGeben Sie eine Zeichenkette von 0 und 1 ein: ", NULL, NULL); int result = convertBinaryStrToInt(toConvert); printf("\nAusgabe (in Dezimal): %d\n", result); } - if(InputProg == 1){ + if(InputOptionsMenu == 1){ int toConvert = usergetd("\nGeben Sie eine Ganzzahl ein: ", NULL, NULL); char* result = convertIntToBinaryStr(toConvert); printf("\nAusgabe (in Binaer): %s\n", result); free(result); } } - if(InputSys == 1){ - if(InputProg == 0){ + if(InputMainMenu == 1){ + if(InputOptionsMenu == 0){ char* toConvert = usergets("\nGeben Sie eine Zeichenkette im Hexadezimal-Format ein: ", NULL, NULL); int result = convertHexStrToInt(toConvert); printf("\nAusgabe (in Dezimal): %d\n", result); } - if(InputProg == 1){ + if(InputOptionsMenu == 1){ int rangeMin = 0; int toConvert = usergetd("\nGeben Sie eine positive Ganzzahl ein: ", &rangeMin, NULL); char* result = convertIntToHex(toConvert);