Browse Source

refactoring: change function variable names in input handling

remotes/origin/Input_Handling
Sophia Weber 12 months ago
parent
commit
2aa9fd94a1
  1. 30
      src/inputHandling.c
  2. 8
      src/inputHandling.h

30
src/inputHandling.c

@ -6,13 +6,13 @@
char formulaBuffer[1000];
void processInput(char* formStr, int length) {
deleteWhitespace(formStr, length);
void processInput(char* formStr, int len) {
deleteWhitespace(formStr, len);
calc_op temp;
memcpy(formulaBuffer, formStr, length);
memcpy(formulaBuffer, formStr, len);
temp.formular = formStr;
temp.functionsType = detectFunctionOperator(formulaBuffer, 10);
if (getNumbers(formulaBuffer, length, &temp) == NULL){
if (getNumbers(formulaBuffer, len, &temp) == NULL){
showStruct(&temp);
} else {
printf("Formular %s not supported", temp.formular);
@ -20,10 +20,10 @@ void processInput(char* formStr, int length) {
}
//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')){
for (int j=stringPos; j < length; j++){
for (int j=stringPos; j < len; j++){
formStr[j]=formStr[j + 1];
}
stringPos--;
@ -32,8 +32,8 @@ void deleteWhitespace(char* formStr, int length){
}
//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]){
case '+': return opAdd;
case '-': return opSub;
@ -47,12 +47,12 @@ op detectFunctionOperator(char* formStr, int length){
}
//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;
int numPos = 0;
char delimiter;
switch (formulaRef->functionsType) {
switch (formRef->functionsType) {
case opAdd:
delimiter = '+';
break;
@ -67,15 +67,15 @@ char* getNumbers(char* formStr, int length, calc_op* formulaRef){ //processInput
break;
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
while (token != NULL) {
formulaRef->inputNumbers[numPos] = atof(token); // String zu double konvertiert
formRef->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
formRef->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;

8
src/inputHandling.h

@ -15,11 +15,11 @@ void* parent;
double result;
}calc_op;
extern void processInput(char* formStr, int length);
extern void processInput(char* formStr, int len);
extern void showStruct(calc_op* formRef);
extern void deleteWhitespace(char* formStr, int length);
extern op detectFunctionOperator(char* formStr, int length);
extern char* getNumbers(char* formStr, int length, calc_op* formulaRef);
extern void deleteWhitespace(char* formStr, int len);
extern op detectFunctionOperator(char* formStr, int len);
extern char* getNumbers(char* formStr, int len, calc_op* formRef);
extern void showStruct(calc_op* formRef);
#endif // INPUTHANDLING_H
Loading…
Cancel
Save