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];
void input(char* formulaString, int length) {
void processInput(char* formulaString, int length) {
deleteWhitespace(formulaString, length);
calc_op temp;
memcpy(formulaBuffer, formulaString, length);
temp.formel = formulaString;
temp.funktionstyp = readFunction(formulaBuffer, 10);
temp.funktionstyp = detectFunctionOperator(formulaBuffer, 10);
if (getNumbers(formulaBuffer, length, &temp) == NULL){
showStruct(&temp);
} else {
@ -32,7 +32,7 @@ void deleteWhitespace(char* formulaString, int length){
}
//Einfachste Rechenoperationen lesen
op readFunction(char* formulaString, int length){
op detectFunctionOperator(char* formulaString, int length){
for(int stringCount=0; stringCount < length; stringCount++){
switch (formulaString[stringCount]){
case '+': return opAdd;
@ -47,7 +47,7 @@ op readFunction(char* formulaString, int length){
}
//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* splitPnt;
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
}
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){
return splitPnt;
} else {

4
src/inputHandling.h

@ -15,10 +15,10 @@ void* parent;
double result;
}calc_op;
extern void input(char* formulaString, int length);
extern void processInput(char* formulaString, int length);
extern void showStruct(calc_op* formulaRef);
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 void showStruct(calc_op* formulaRef);

2
src/main.c

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