Browse Source

refactoring: change struct names

remotes/origin/Input_Handling
Sophia Weber 11 months ago
parent
commit
0f23ca57c1
  1. 20
      src/inputHandling.c
  2. 8
      src/inputHandling.h

20
src/inputHandling.c

@ -10,12 +10,12 @@ void processInput(char* formulaString, int length) {
deleteWhitespace(formulaString, length);
calc_op temp;
memcpy(formulaBuffer, formulaString, length);
temp.formel = formulaString;
temp.funktionstyp = detectFunctionOperator(formulaBuffer, 10);
temp.formular = formulaString;
temp.functionsType = detectFunctionOperator(formulaBuffer, 10);
if (getNumbers(formulaBuffer, length, &temp) == NULL){
showStruct(&temp);
} else {
printf("Formular %s not supported", temp.formel);
printf("Formular %s not supported", temp.formular);
}
}
@ -52,7 +52,7 @@ char* getNumbers(char* formulaString, int length, calc_op* formulaRef){ //proces
char* splitPnt;
int numPos = 0;
char delimiter;
switch (formulaRef->funktionstyp) {
switch (formulaRef->functionsType) {
case opAdd:
delimiter = '+';
break;
@ -70,12 +70,12 @@ char* getNumbers(char* formulaString, int length, calc_op* formulaRef){ //proces
// memcpy(tmp, formulaString, length); //string kopiert
char *token = strtok(formulaString, &delimiter); //An der Stelle von dem ersten Plus wird ein NULL (Stringende) gesetzt
while (token != NULL) {
formulaRef->array[numPos] = atof(token); // String zu double konvertiert
formulaRef->inputNumbers[numPos] = atof(token); // String zu double konvertiert
numPos++;
splitPnt = token;
token = strtok(NULL, "+"); //Sucht von der letzten Plus-Stelle an weiter
}
formulaRef->arraylength=numPos; //Länge des Arrays (also zu berechnende Zahlen) gespeichert
formulaRef->arrayLength=numPos; //Länge des Arrays (also zu berechnende Zahlen) gespeichert
op type = detectFunctionOperator(splitPnt, strlen(splitPnt) + 1);
if (type != opNotSupported && type != opEmpty){
return splitPnt;
@ -85,8 +85,8 @@ char* getNumbers(char* formulaString, int length, calc_op* formulaRef){ //proces
}
void showStruct(calc_op* formulaRef){
printf("Berechnung: %s\n", formulaRef->formel);
switch (formulaRef->funktionstyp) {
printf("Berechnung: %s\n", formulaRef->formular);
switch (formulaRef->functionsType) {
case opAdd:
printf("Rechenoperation: Addition\n"); break;
case opSub:
@ -99,8 +99,8 @@ void showStruct(calc_op* formulaRef){
printf("Fehler bei Auswahl der Rechenoperationen \n");
}
printf("Calculation Variables:\n");
for (int arrayCount = 0; arrayCount < formulaRef->arraylength; ++arrayCount) {
printf("Array[%i] = %f\n", arrayCount, formulaRef->array[arrayCount]);
for (int arrayCount = 0; arrayCount < formulaRef->arrayLength; ++arrayCount) {
printf("Array[%i] = %f\n", arrayCount, formulaRef->inputNumbers[arrayCount]);
}
printf("Result: %f", formulaRef->result);
}

8
src/inputHandling.h

@ -6,10 +6,10 @@ typedef enum{
}op;
typedef struct {
op funktionstyp;
char* formel;
double array[10];
int arraylength;
op functionsType;
char* formular;
double inputNumbers[10];
int arrayLength;
void* child;
void* parent;
double result;

Loading…
Cancel
Save