Browse Source

refactoring: unambiguous variables

remotes/origin/Input_Handling
Sophia Weber 11 months ago
parent
commit
443b8b8a9a
  1. 22
      src/inputHandling.c

22
src/inputHandling.c

@ -26,9 +26,9 @@ void input(char* formulaString, int length) {
//Leerzeichen löschen
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];
}
}
@ -37,8 +37,8 @@ void deleteWhitespace(char* formulaString, int length){
//Einfachste Rechenoperationen lesen
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 opSub;
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 tmp[length];
char* splitPnt;
int i = 0;
int numPos = 0;
char delimiter;
switch (formulaRef->funktionstyp) {
case opAdd:
@ -74,12 +74,12 @@ char* getNumbers(char* formulaString, int length, calc_op* formulaRef){ //input
// memcpy(tmp, formulaString, length); //string kopiert
char *token = strtok(formulaString, &delimiter); //An der Stelle von dem ersten Plus wird ein NULL (Stringende) gesetzt
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;
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);
if (type != opNotSupported && type != opEmpty){
return splitPnt;
@ -103,8 +103,8 @@ void showStruct(calc_op* formulaRef){
printf("Fehler bei Auswahl der Rechenoperationen \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);
}
Loading…
Cancel
Save