Browse Source

Created Function to find calculation function type

remotes/origin/Input_Handling
Sophia Weber 11 months ago
parent
commit
53f5b6af7e
  1. 16
      src/inputHandling.c
  2. 2
      src/inputHandling.h

16
src/inputHandling.c

@ -4,11 +4,13 @@
char a[STRINGL];
void deleteWhitespace();
op readFunction(char* data, int length);
void input() {
printf("Geben Sie eine Rechenoperation ein (Bsp.: 1+1):\n");
fgets(a, STRINGL, stdin); //fgets statt scanf, holt den kompletten String inkl. Whitespace
deleteWhitespace();
op b = readFunction(a, 10);
printf("Ihre Berechnung: %s \n", a);
}
@ -23,4 +25,16 @@ void deleteWhitespace(){
}
}
//Einfachste Rechenoperationen lesen
op readFunction(char* data, int length){
for(int i=0; i<length; i++){
switch (data[i]){
case '+': return opAdd;
case '-': return opSub;
case '/': return opDiv;
case '*': return opMult;
case '^': return opExp;
}
}
return opNotSupported;
}

2
src/inputHandling.h

@ -2,7 +2,7 @@
#define INPUTHANDLING_H
typedef enum{
opAdd, opSub, opDiv, opMult, opExp, opLog
opAdd, opSub, opDiv, opMult, opExp, opLog, opNotSupported
}op;
typedef struct {

Loading…
Cancel
Save