Sophia Weber
12 months ago
8 changed files with 329 additions and 52 deletions
-
1project.yml
-
119src/inputHandling.c
-
23src/inputHandling.h
-
26src/main.c
-
22src/outputHandling.c
-
10src/outputHandling.h
-
151test/test_inputHandling.c
-
29test/test_outputHandling.c
@ -1,6 +1,30 @@ |
|||||
#include "helloWorld.h" |
#include "helloWorld.h" |
||||
#include "inputHandling.h" |
#include "inputHandling.h" |
||||
|
#include "outputHandling.h" |
||||
|
#include <string.h> |
||||
|
#include <stdio.h> |
||||
|
#include <stdlib.h> |
||||
|
#define STRING_LENGTH 200 |
||||
|
|
||||
|
char inputBuffer[STRING_LENGTH] = {0}; |
||||
|
|
||||
void main() { |
void main() { |
||||
input(); |
|
||||
|
calc_op *result = NULL; |
||||
|
printf("Geben Sie eine Rechenoperation ein (Bsp.: 1+1):\n"); |
||||
|
fgets(inputBuffer, STRING_LENGTH, stdin); //fgets statt scanf, holt den kompletten String inkl. Whitespace |
||||
|
processInput(inputBuffer, strlen(inputBuffer)); |
||||
|
do { |
||||
|
result = getNextCalc(); |
||||
|
if (result == NULL) { |
||||
|
break; |
||||
|
} |
||||
|
if (result->functionsType==opResult) { |
||||
|
result->result = result->inputNumbers[0]; |
||||
|
showResult(result); |
||||
|
break; |
||||
|
} |
||||
|
/* Calculation*/ |
||||
|
result->result = 65478; |
||||
|
} while (1); |
||||
|
result = getNextCalc(); |
||||
} |
} |
@ -0,0 +1,22 @@ |
|||||
|
#include <stdio.h> |
||||
|
#include "outputHandling.h" |
||||
|
#include "inputHandling.h" |
||||
|
|
||||
|
void buildHexString(char* string, int num) { |
||||
|
sprintf(string, "0x%X", num); |
||||
|
} |
||||
|
|
||||
|
void buildOctString(char* string, int num) { |
||||
|
sprintf(string, "%o", num); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void showResult(calc_op* res) { |
||||
|
char string[60] = {0}; |
||||
|
printf("Das Ergebnis ist: %f\n", res->result); |
||||
|
printf("Das Ergebnis in dec: %i\n",(int)res->result); |
||||
|
buildHexString(string, (int) res->result); |
||||
|
printf("Das Ergebnis in buildHexString: 0x%s\n", string); ; |
||||
|
buildOctString(string, (int) res->result); |
||||
|
printf("Das Ergebnis in buildOctString: %s\n", string); ; |
||||
|
} |
@ -0,0 +1,10 @@ |
|||||
|
#ifndef OUTPUTHANDLING_H |
||||
|
#define OUTPUTHANDLING_H |
||||
|
|
||||
|
#include "inputHandling.h" |
||||
|
|
||||
|
extern void buildHexString(char* string, int num); |
||||
|
extern void buildOctString(char* string, int num); |
||||
|
extern void showResult(calc_op* res); |
||||
|
|
||||
|
#endif // OUTPUTHANDLING_H |
@ -0,0 +1,29 @@ |
|||||
|
#ifdef TEST |
||||
|
|
||||
|
#include "unity.h" |
||||
|
|
||||
|
#include "outputHandling.h" |
||||
|
|
||||
|
char string[100]= {0}; |
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void test_outputHandling_buildOctString(void) |
||||
|
{ |
||||
|
buildOctString(string, 5555555); |
||||
|
TEST_ASSERT_EQUAL_STRING("25142543", string); |
||||
|
} |
||||
|
|
||||
|
void test_outputHandling_buildHexString(void) |
||||
|
{ |
||||
|
buildHexString(string, 5555555); |
||||
|
TEST_ASSERT_EQUAL_STRING("0x54C563", string); |
||||
|
} |
||||
|
|
||||
|
#endif // TEST |
Write
Preview
Loading…
Cancel
Save
Reference in new issue