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