|
@ -10,12 +10,12 @@ void processInput(char* formulaString, int length) { |
|
|
deleteWhitespace(formulaString, length); |
|
|
deleteWhitespace(formulaString, length); |
|
|
calc_op temp; |
|
|
calc_op temp; |
|
|
memcpy(formulaBuffer, formulaString, length); |
|
|
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){ |
|
|
if (getNumbers(formulaBuffer, length, &temp) == NULL){ |
|
|
showStruct(&temp); |
|
|
showStruct(&temp); |
|
|
} else { |
|
|
} 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; |
|
|
char* splitPnt; |
|
|
int numPos = 0; |
|
|
int numPos = 0; |
|
|
char delimiter; |
|
|
char delimiter; |
|
|
switch (formulaRef->funktionstyp) { |
|
|
|
|
|
|
|
|
switch (formulaRef->functionsType) { |
|
|
case opAdd: |
|
|
case opAdd: |
|
|
delimiter = '+'; |
|
|
delimiter = '+'; |
|
|
break; |
|
|
break; |
|
@ -70,12 +70,12 @@ char* getNumbers(char* formulaString, int length, calc_op* formulaRef){ //proces |
|
|
// memcpy(tmp, formulaString, length); //string kopiert |
|
|
// memcpy(tmp, formulaString, length); //string kopiert |
|
|
char *token = strtok(formulaString, &delimiter); //An der Stelle von dem ersten Plus wird ein NULL (Stringende) gesetzt |
|
|
char *token = strtok(formulaString, &delimiter); //An der Stelle von dem ersten Plus wird ein NULL (Stringende) gesetzt |
|
|
while (token != NULL) { |
|
|
while (token != NULL) { |
|
|
formulaRef->array[numPos] = atof(token); // String zu double konvertiert |
|
|
|
|
|
|
|
|
formulaRef->inputNumbers[numPos] = atof(token); // String zu double konvertiert |
|
|
numPos++; |
|
|
numPos++; |
|
|
splitPnt = token; |
|
|
splitPnt = token; |
|
|
token = strtok(NULL, "+"); //Sucht von der letzten Plus-Stelle an weiter |
|
|
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); |
|
|
op type = detectFunctionOperator(splitPnt, strlen(splitPnt) + 1); |
|
|
if (type != opNotSupported && type != opEmpty){ |
|
|
if (type != opNotSupported && type != opEmpty){ |
|
|
return splitPnt; |
|
|
return splitPnt; |
|
@ -85,8 +85,8 @@ char* getNumbers(char* formulaString, int length, calc_op* formulaRef){ //proces |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void showStruct(calc_op* formulaRef){ |
|
|
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: |
|
|
case opAdd: |
|
|
printf("Rechenoperation: Addition\n"); break; |
|
|
printf("Rechenoperation: Addition\n"); break; |
|
|
case opSub: |
|
|
case opSub: |
|
@ -99,8 +99,8 @@ void showStruct(calc_op* formulaRef){ |
|
|
printf("Fehler bei Auswahl der Rechenoperationen \n"); |
|
|
printf("Fehler bei Auswahl der Rechenoperationen \n"); |
|
|
} |
|
|
} |
|
|
printf("Calculation Variables:\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); |
|
|
printf("Result: %f", formulaRef->result); |
|
|
} |
|
|
} |