From b283647e58aa1b13a9913df11605f14f0a1686d8 Mon Sep 17 00:00:00 2001 From: Sophia Weber Date: Sun, 28 Jan 2024 19:16:09 +0100 Subject: [PATCH] add get next calculation function --- src/inputHandling.c | 9 +++++++++ src/inputHandling.h | 5 +++-- src/main.c | 11 ++++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/inputHandling.c b/src/inputHandling.c index 867402b..e9d8217 100644 --- a/src/inputHandling.c +++ b/src/inputHandling.c @@ -6,6 +6,7 @@ char formulaBuffer[1000]; calc_op* mainCalc = NULL; +calc_op* currentCalc = NULL; void processInput(char* formStr, int len) { deleteWhitespace(formStr, len); @@ -23,6 +24,14 @@ void processInput(char* formStr, int len) { } } +calc_op* getNextCalc(){ + if (currentCalc != NULL){ + free(currentCalc); + } + currentCalc = mainCalc; // get ext calculation + return currentCalc; +} + //Leerzeichen löschen void deleteWhitespace(char* formStr, int len){ for(int stringPos=0; stringPos < len; stringPos++){ diff --git a/src/inputHandling.h b/src/inputHandling.h index e5635de..9939eae 100644 --- a/src/inputHandling.h +++ b/src/inputHandling.h @@ -10,8 +10,8 @@ op functionsType; char* formular; double inputNumbers[10]; int arrayLength; -void* child; -void* parent; +void* child[10]; // all children structs which depends on this struct +void* parent; // the parent struct which this struct depends on double result; }calc_op; @@ -21,5 +21,6 @@ extern void deleteWhitespace(char* formStr, int len); extern op detectFunctionOperator(char* formStr, int len); extern char* getNumbers(char* formStr, int len, calc_op* formRef); extern void showStruct(calc_op* formRef); +extern calc_op* getNextCalc(); #endif // INPUTHANDLING_H diff --git a/src/main.c b/src/main.c index 6a55347..ac2fea4 100644 --- a/src/main.c +++ b/src/main.c @@ -9,10 +9,15 @@ char inputBuffer[STRING_LENGTH] = {0}; void main() { - calc_op result; + calc_op *result = NULL; printf("Geben Sie eine Rechenoperation ein (Bsp.: 1+1):\n"); fgets(inputBuffer, STRING_LENGTH, stdin); //fgets statt scanf, holt den kompletten String inkl. Whitespace processInput(inputBuffer, strlen(inputBuffer)); - result.result = 65478; - showResult(&result); + result = getNextCalc(); + if (result!=NULL){ + /* Calculation*/ + result->result = 65478; + showResult(result); + } + }