aboutsummaryrefslogtreecommitdiff
path: root/7.5/op.c
diff options
context:
space:
mode:
Diffstat (limited to '7.5/op.c')
-rw-r--r--7.5/op.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/7.5/op.c b/7.5/op.c
new file mode 100644
index 0000000..e7640e6
--- /dev/null
+++ b/7.5/op.c
@@ -0,0 +1,32 @@
+#include <stdio.h>
+#include <ctype.h>
+#include "op.h"
+
+char getop(char *op, size_t len)
+{
+ size_t i;
+
+ *op = '\0'; // if scanf fails
+ do {
+ scanf("%c", op);
+ } while (isblank(*op));
+
+ if (!isdigit(*op))
+ return *op;
+
+ i = 1;
+ do {
+ scanf("%c", op + i);
+ } while (isdigit(op[i]) && ++i < len);
+
+ if (op[i] == '.') {
+ i++;
+ do {
+ scanf("%c", op + i);
+ } while (isdigit(op[i]) && ++i < len);
+ }
+
+ ungetc(op[i], stdin);
+ op[i] = '\0';
+ return NUM;
+}