Browse Source

refactoring: function names

remotes/origin/Input_Handling
Sophia Weber 11 months ago
parent
commit
6245159db6
  1. 10
      src/inputHandling.c
  2. 4
      src/inputHandling.h
  3. 2
      src/main.c

10
src/inputHandling.c

@ -6,12 +6,12 @@
char formulaBuffer[1000]; char formulaBuffer[1000];
void input(char* formulaString, int length) {
void processInput(char* formulaString, int length) {
deleteWhitespace(formulaString, length); deleteWhitespace(formulaString, length);
calc_op temp; calc_op temp;
memcpy(formulaBuffer, formulaString, length); memcpy(formulaBuffer, formulaString, length);
temp.formel = formulaString; temp.formel = formulaString;
temp.funktionstyp = readFunction(formulaBuffer, 10);
temp.funktionstyp = detectFunctionOperator(formulaBuffer, 10);
if (getNumbers(formulaBuffer, length, &temp) == NULL){ if (getNumbers(formulaBuffer, length, &temp) == NULL){
showStruct(&temp); showStruct(&temp);
} else { } else {
@ -32,7 +32,7 @@ void deleteWhitespace(char* formulaString, int length){
} }
//Einfachste Rechenoperationen lesen //Einfachste Rechenoperationen lesen
op readFunction(char* formulaString, int length){
op detectFunctionOperator(char* formulaString, int length){
for(int stringCount=0; stringCount < length; stringCount++){ for(int stringCount=0; stringCount < length; stringCount++){
switch (formulaString[stringCount]){ switch (formulaString[stringCount]){
case '+': return opAdd; case '+': return opAdd;
@ -47,7 +47,7 @@ op readFunction(char* formulaString, int length){
} }
//Zahlen auslesen (+) //Zahlen auslesen (+)
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){ //processInput sind: string, länge vom String, berechnungsstruct
// char tmp[length]; // char tmp[length];
char* splitPnt; char* splitPnt;
int numPos = 0; int numPos = 0;
@ -76,7 +76,7 @@ char* getNumbers(char* formulaString, int length, calc_op* formulaRef){ //input
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 formulaRef->arraylength=numPos; //Länge des Arrays (also zu berechnende Zahlen) gespeichert
op type = readFunction(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;
} else { } else {

4
src/inputHandling.h

@ -15,10 +15,10 @@ void* parent;
double result; double result;
}calc_op; }calc_op;
extern void input(char* formulaString, int length);
extern void processInput(char* formulaString, int length);
extern void showStruct(calc_op* formulaRef); extern void showStruct(calc_op* formulaRef);
extern void deleteWhitespace(char* formulaString, int length); extern void deleteWhitespace(char* formulaString, int length);
extern op readFunction(char* formulaString, int length);
extern op detectFunctionOperator(char* formulaString, int length);
extern char* getNumbers(char* formulaString, int length, calc_op* formulaRef); extern char* getNumbers(char* formulaString, int length, calc_op* formulaRef);
extern void showStruct(calc_op* formulaRef); extern void showStruct(calc_op* formulaRef);

2
src/main.c

@ -10,5 +10,5 @@ char a[STRINGL] = {0};
void main() { void main() {
printf("Geben Sie eine Rechenoperation ein (Bsp.: 1+1):\n"); printf("Geben Sie eine Rechenoperation ein (Bsp.: 1+1):\n");
fgets(a, STRINGL, stdin); //fgets statt scanf, holt den kompletten String inkl. Whitespace fgets(a, STRINGL, stdin); //fgets statt scanf, holt den kompletten String inkl. Whitespace
input(a, strlen(a));
processInput(a, strlen(a));
} }
Loading…
Cancel
Save