Browse Source

add get next calculation function

remotes/origin/Input_Handling
Sophia Weber 11 months ago
parent
commit
b283647e58
  1. 9
      src/inputHandling.c
  2. 5
      src/inputHandling.h
  3. 11
      src/main.c

9
src/inputHandling.c

@ -6,6 +6,7 @@
char formulaBuffer[1000]; char formulaBuffer[1000];
calc_op* mainCalc = NULL; calc_op* mainCalc = NULL;
calc_op* currentCalc = NULL;
void processInput(char* formStr, int len) { void processInput(char* formStr, int len) {
deleteWhitespace(formStr, 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 //Leerzeichen löschen
void deleteWhitespace(char* formStr, int len){ void deleteWhitespace(char* formStr, int len){
for(int stringPos=0; stringPos < len; stringPos++){ for(int stringPos=0; stringPos < len; stringPos++){

5
src/inputHandling.h

@ -10,8 +10,8 @@ op functionsType;
char* formular; char* formular;
double inputNumbers[10]; double inputNumbers[10];
int arrayLength; 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; double result;
}calc_op; }calc_op;
@ -21,5 +21,6 @@ extern void deleteWhitespace(char* formStr, int len);
extern op detectFunctionOperator(char* formStr, int len); extern op detectFunctionOperator(char* formStr, int len);
extern char* getNumbers(char* formStr, int len, calc_op* formRef); extern char* getNumbers(char* formStr, int len, calc_op* formRef);
extern void showStruct(calc_op* formRef); extern void showStruct(calc_op* formRef);
extern calc_op* getNextCalc();
#endif // INPUTHANDLING_H #endif // INPUTHANDLING_H

11
src/main.c

@ -9,10 +9,15 @@
char inputBuffer[STRING_LENGTH] = {0}; char inputBuffer[STRING_LENGTH] = {0};
void main() { void main() {
calc_op result;
calc_op *result = NULL;
printf("Geben Sie eine Rechenoperation ein (Bsp.: 1+1):\n"); printf("Geben Sie eine Rechenoperation ein (Bsp.: 1+1):\n");
fgets(inputBuffer, STRING_LENGTH, stdin); //fgets statt scanf, holt den kompletten String inkl. Whitespace fgets(inputBuffer, STRING_LENGTH, stdin); //fgets statt scanf, holt den kompletten String inkl. Whitespace
processInput(inputBuffer, strlen(inputBuffer)); processInput(inputBuffer, strlen(inputBuffer));
result.result = 65478;
showResult(&result);
result = getNextCalc();
if (result!=NULL){
/* Calculation*/
result->result = 65478;
showResult(result);
}
} }
Loading…
Cancel
Save