|
@ -26,9 +26,9 @@ void input(char* formulaString, int length) { |
|
|
|
|
|
|
|
|
//Leerzeichen löschen |
|
|
//Leerzeichen löschen |
|
|
void deleteWhitespace(char* formulaString, int length){ |
|
|
void deleteWhitespace(char* formulaString, int length){ |
|
|
for(int i=0; i<length; i++){ |
|
|
|
|
|
if((formulaString[i] == ' ') || (formulaString[i] == '\n') || (formulaString[i] == '\r')){ |
|
|
|
|
|
for (int j=i; j<length; j++){ |
|
|
|
|
|
|
|
|
for(int stringPos=0; stringPos < length; stringPos++){ |
|
|
|
|
|
if((formulaString[stringPos] == ' ') || (formulaString[stringPos] == '\n') || (formulaString[stringPos] == '\r')){ |
|
|
|
|
|
for (int j=stringPos; j < length; j++){ |
|
|
formulaString[j]=formulaString[j + 1]; |
|
|
formulaString[j]=formulaString[j + 1]; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -37,8 +37,8 @@ void deleteWhitespace(char* formulaString, int length){ |
|
|
|
|
|
|
|
|
//Einfachste Rechenoperationen lesen |
|
|
//Einfachste Rechenoperationen lesen |
|
|
op readFunction(char* formulaString, int length){ |
|
|
op readFunction(char* formulaString, int length){ |
|
|
for(int i=0; i<length; i++){ |
|
|
|
|
|
switch (formulaString[i]){ |
|
|
|
|
|
|
|
|
for(int stringCount=0; stringCount < length; stringCount++){ |
|
|
|
|
|
switch (formulaString[stringCount]){ |
|
|
case '+': return opAdd; |
|
|
case '+': return opAdd; |
|
|
case '-': return opSub; |
|
|
case '-': return opSub; |
|
|
case '/': return opDiv; |
|
|
case '/': return opDiv; |
|
@ -54,7 +54,7 @@ op readFunction(char* formulaString, int length){ |
|
|
char* getNumbers(char* formulaString, int length, calc_op* formulaRef){ //input sind: string, länge vom String, berechnungsstruct |
|
|
char* getNumbers(char* formulaString, int length, calc_op* formulaRef){ //input sind: string, länge vom String, berechnungsstruct |
|
|
// char tmp[length]; |
|
|
// char tmp[length]; |
|
|
char* splitPnt; |
|
|
char* splitPnt; |
|
|
int i = 0; |
|
|
|
|
|
|
|
|
int numPos = 0; |
|
|
char delimiter; |
|
|
char delimiter; |
|
|
switch (formulaRef->funktionstyp) { |
|
|
switch (formulaRef->funktionstyp) { |
|
|
case opAdd: |
|
|
case opAdd: |
|
@ -74,12 +74,12 @@ char* getNumbers(char* formulaString, int length, calc_op* formulaRef){ //input |
|
|
// 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[i] = atof(token); // String zu double konvertiert |
|
|
|
|
|
i++; |
|
|
|
|
|
|
|
|
formulaRef->array[numPos] = atof(token); // String zu double konvertiert |
|
|
|
|
|
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=i; //Länge des Arrays (also zu berechnende Zahlen) gespeichert |
|
|
|
|
|
|
|
|
formulaRef->arraylength=numPos; //Länge des Arrays (also zu berechnende Zahlen) gespeichert |
|
|
op type = readFunction(splitPnt, strlen(splitPnt)+1); |
|
|
op type = readFunction(splitPnt, strlen(splitPnt)+1); |
|
|
if (type != opNotSupported && type != opEmpty){ |
|
|
if (type != opNotSupported && type != opEmpty){ |
|
|
return splitPnt; |
|
|
return splitPnt; |
|
@ -103,8 +103,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 i = 0; i < formulaRef->arraylength; ++i) { |
|
|
|
|
|
printf("Array[%i] = %f\n", i, formulaRef->array[i]); |
|
|
|
|
|
|
|
|
for (int arrayCount = 0; arrayCount < formulaRef->arraylength; ++arrayCount) { |
|
|
|
|
|
printf("Array[%i] = %f\n", arrayCount, formulaRef->array[arrayCount]); |
|
|
} |
|
|
} |
|
|
printf("Result: %f", formulaRef->result); |
|
|
printf("Result: %f", formulaRef->result); |
|
|
} |
|
|
} |