Browse Source

change input mask to main

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

23
src/inputHandling.c

@ -2,25 +2,22 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#define STRINGL 200
char a[STRINGL];
void deleteWhitespace();
char data[1000];
void deleteWhitespace(char* a, int length);
op readFunction(char* data, int length); op readFunction(char* data, int length);
char* getnumbers(char* data, int length, calc_op* structure_ref); char* getnumbers(char* data, int length, calc_op* structure_ref);
void printstruct(calc_op* formula); void printstruct(calc_op* formula);
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();
void input(char* a, int length) {
deleteWhitespace(a, length);
calc_op temp; calc_op temp;
char data[STRINGL];
memcpy(data,a,STRINGL);
memcpy(data,a,length);
temp.formel = a; temp.formel = a;
temp.funktionstyp = readFunction(data, 10); temp.funktionstyp = readFunction(data, 10);
if (getnumbers(data,STRINGL, &temp) == NULL){
if (getnumbers(data,length, &temp) == NULL){
printstruct(&temp); printstruct(&temp);
} else { } else {
printf("Formular %s not supported", temp.formel); printf("Formular %s not supported", temp.formel);
@ -28,10 +25,10 @@ void input() {
} }
//Leerzeichen löschen //Leerzeichen löschen
void deleteWhitespace(){
for(int i=0; i<STRINGL; i++){
void deleteWhitespace(char* a, int length){
for(int i=0; i<length; i++){
if((a[i]==' ')||(a[i]=='\n')||(a[i]=='\r')){ if((a[i]==' ')||(a[i]=='\n')||(a[i]=='\r')){
for (int j=i; j<STRINGL; j++){
for (int j=i; j<length; j++){
a[j]=a[j+1]; a[j]=a[j+1];
} }
} }

4
src/inputHandling.h

@ -15,7 +15,7 @@ void* parent;
double result; double result;
}calc_op; }calc_op;
extern void input();
extern void input(char* a, int length);
extern void printstruct(calc_op* formula);
#endif // INPUTHANDLING_H #endif // INPUTHANDLING_H

10
src/main.c

@ -1,6 +1,14 @@
#include "helloWorld.h" #include "helloWorld.h"
#include "inputHandling.h" #include "inputHandling.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define STRINGL 200
char a[STRINGL] = {0};
void main() { void main() {
input();
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));
} }
Loading…
Cancel
Save