Skip to content

Commit 41530d4

Browse files
author
Till Johanndeiter
committed
Add valueTable.c
1 parent 832fa5e commit 41530d4

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

valueTable.c

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include <ctype.h>
2+
#include <f2fs_fs.h>
3+
#include<math.h>
4+
5+
#define INVALID_INPUT "Invalid Argument combination! Enter function [-cos -sin -tan] start end and offset\n"
6+
7+
bool isValidArgumentCombination(int argc, const char *const *argv);
8+
9+
double (*getFunction(const char *const *argv))(double);
10+
11+
void printValueTable(const char *const *argv);
12+
13+
bool isInvalidFktArgument();
14+
15+
int main(int argc, char const *argv[]) {
16+
17+
if (isValidArgumentCombination(argc, argv)) {
18+
printValueTable(argv);
19+
} else {
20+
printf(INVALID_INPUT);
21+
}
22+
23+
return 0;
24+
}
25+
26+
void printValueTable(const char *const *argv) {
27+
28+
double (*trigonometricFkt)(double) = getFunction(argv);
29+
if (isInvalidFktArgument(trigonometricFkt)) {
30+
printf(INVALID_INPUT);
31+
} else {
32+
float start = atof(argv[2]);
33+
float end = atof(argv[3]);
34+
float offset = atof(argv[4]);
35+
36+
char fktNameBuff[4];
37+
memcpy(fktNameBuff, &argv[1][1], 3);
38+
fktNameBuff[3] = '\0';
39+
40+
while (start <= end) {
41+
printf("Value for %s(%f.10) : %f.10\n", fktNameBuff, start, trigonometricFkt(start));
42+
start += offset;
43+
}
44+
}
45+
}
46+
47+
double (*getFunction(const char *const *argv))(double) {
48+
49+
double (*trigonometricFkt)(double) = NULL;
50+
51+
if (strcmp("-cos", argv[1]) == 0) {
52+
trigonometricFkt = cos;
53+
} else if (strcmp("-sin", argv[1]) == 0) {
54+
trigonometricFkt = sin;
55+
} else if (strcmp("-tan", argv[1]) == 0) {
56+
trigonometricFkt = tan;
57+
}
58+
return trigonometricFkt;
59+
}
60+
61+
bool isInvalidFktArgument(double (*trigonometricFkt)(double)) {
62+
return trigonometricFkt == NULL;
63+
}
64+
65+
bool isValidArgumentCombination(int argc, const char *const *argv) {
66+
return argc > 1
67+
&& isdigit(*argv[2])
68+
&& isdigit(*argv[3])
69+
&& isdigit(*argv[4]);
70+
}
71+
72+
float ownTan(float f) {
73+
return f * M_PI / 180;
74+
}

0 commit comments

Comments
 (0)