-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcalc.c
65 lines (52 loc) · 1.13 KB
/
pcalc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* TODO:
* - Add support for optinal custom divsor
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int stoi(const char* str, const int offset) {
int sign = 1;
int i = offset;
char c = str[i];
while (c == '-' || c == '+') {
if (c == '-') {
sign *= -1;
}
i++;
c = str[i];
}
return -1;
}
struct Token {
int power;
int cof;
};
const char USAGE[] = "pcalc <polynomial (x^3+2x^2+9x+8)>\n";
int main(const int argc, const char** argv) {
if (argc != 2) {
fprintf(stderr, USAGE);
exit(-1);
}
int i = 0;
char c;
while (c != '\0') {
c = argv[1][i];
if (isdigit(c) || c == '-' || c == '+') {
const int offset = i;
while (c == '-' || c == '+') {
i++;
c = argv[1][i];
}
while (isdigit(c)) {
i++;
c = argv[1][i];
}
int num = stoi(argv[1], offset);
(void) num;
}
else if (isalpha(c)) {
/* PARSE WITHOUT COF */
}
}
return 0;
}