|
@ -6,13 +6,13 @@ |
|
|
|
|
|
|
|
|
char formulaBuffer[1000]; |
|
|
char formulaBuffer[1000]; |
|
|
|
|
|
|
|
|
void processInput(char* formStr, int length) { |
|
|
|
|
|
deleteWhitespace(formStr, length); |
|
|
|
|
|
|
|
|
void processInput(char* formStr, int len) { |
|
|
|
|
|
deleteWhitespace(formStr, len); |
|
|
calc_op temp; |
|
|
calc_op temp; |
|
|
memcpy(formulaBuffer, formStr, length); |
|
|
|
|
|
|
|
|
memcpy(formulaBuffer, formStr, len); |
|
|
temp.formular = formStr; |
|
|
temp.formular = formStr; |
|
|
temp.functionsType = detectFunctionOperator(formulaBuffer, 10); |
|
|
temp.functionsType = detectFunctionOperator(formulaBuffer, 10); |
|
|
if (getNumbers(formulaBuffer, length, &temp) == NULL){ |
|
|
|
|
|
|
|
|
if (getNumbers(formulaBuffer, len, &temp) == NULL){ |
|
|
showStruct(&temp); |
|
|
showStruct(&temp); |
|
|
} else { |
|
|
} else { |
|
|
printf("Formular %s not supported", temp.formular); |
|
|
printf("Formular %s not supported", temp.formular); |
|
@ -20,10 +20,10 @@ void processInput(char* formStr, int length) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Leerzeichen löschen |
|
|
//Leerzeichen löschen |
|
|
void deleteWhitespace(char* formStr, int length){ |
|
|
|
|
|
for(int stringPos=0; stringPos < length; stringPos++){ |
|
|
|
|
|
|
|
|
void deleteWhitespace(char* formStr, int len){ |
|
|
|
|
|
for(int stringPos=0; stringPos < len; stringPos++){ |
|
|
if((formStr[stringPos] == ' ') || (formStr[stringPos] == '\n') || (formStr[stringPos] == '\r')){ |
|
|
if((formStr[stringPos] == ' ') || (formStr[stringPos] == '\n') || (formStr[stringPos] == '\r')){ |
|
|
for (int j=stringPos; j < length; j++){ |
|
|
|
|
|
|
|
|
for (int j=stringPos; j < len; j++){ |
|
|
formStr[j]=formStr[j + 1]; |
|
|
formStr[j]=formStr[j + 1]; |
|
|
} |
|
|
} |
|
|
stringPos--; |
|
|
stringPos--; |
|
@ -32,8 +32,8 @@ void deleteWhitespace(char* formStr, int length){ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Einfachste Rechenoperationen lesen |
|
|
//Einfachste Rechenoperationen lesen |
|
|
op detectFunctionOperator(char* formStr, int length){ |
|
|
|
|
|
for(int stringCount=0; stringCount < length; stringCount++){ |
|
|
|
|
|
|
|
|
op detectFunctionOperator(char* formStr, int len){ |
|
|
|
|
|
for(int stringCount=0; stringCount < len; stringCount++){ |
|
|
switch (formStr[stringCount]){ |
|
|
switch (formStr[stringCount]){ |
|
|
case '+': return opAdd; |
|
|
case '+': return opAdd; |
|
|
case '-': return opSub; |
|
|
case '-': return opSub; |
|
@ -47,12 +47,12 @@ op detectFunctionOperator(char* formStr, int length){ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Zahlen auslesen (+) |
|
|
//Zahlen auslesen (+) |
|
|
char* getNumbers(char* formStr, int length, calc_op* formulaRef){ //processInput sind: string, länge vom String, berechnungsstruct |
|
|
|
|
|
// char tmp[length]; |
|
|
|
|
|
|
|
|
char* getNumbers(char* formStr, int len, calc_op* formRef){ //processInput sind: string, länge vom String, berechnungsstruct |
|
|
|
|
|
// char tmp[len]; |
|
|
char* splitPnt; |
|
|
char* splitPnt; |
|
|
int numPos = 0; |
|
|
int numPos = 0; |
|
|
char delimiter; |
|
|
char delimiter; |
|
|
switch (formulaRef->functionsType) { |
|
|
|
|
|
|
|
|
switch (formRef->functionsType) { |
|
|
case opAdd: |
|
|
case opAdd: |
|
|
delimiter = '+'; |
|
|
delimiter = '+'; |
|
|
break; |
|
|
break; |
|
@ -67,15 +67,15 @@ char* getNumbers(char* formStr, int length, calc_op* formulaRef){ //processInput |
|
|
break; |
|
|
break; |
|
|
default: return NULL; |
|
|
default: return NULL; |
|
|
} |
|
|
} |
|
|
// memcpy(tmp, formStr, length); //string kopiert |
|
|
|
|
|
|
|
|
// memcpy(tmp, formStr, len); //string kopiert |
|
|
char *token = strtok(formStr, &delimiter); //An der Stelle von dem ersten Plus wird ein NULL (Stringende) gesetzt |
|
|
char *token = strtok(formStr, &delimiter); //An der Stelle von dem ersten Plus wird ein NULL (Stringende) gesetzt |
|
|
while (token != NULL) { |
|
|
while (token != NULL) { |
|
|
formulaRef->inputNumbers[numPos] = atof(token); // String zu double konvertiert |
|
|
|
|
|
|
|
|
formRef->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 |
|
|
|
|
|
|
|
|
formRef->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; |
|
|