diff options
author | sinanmohd <sinan@firemail.cc> | 2023-05-13 14:52:00 +0530 |
---|---|---|
committer | sinanmohd <sinan@firemail.cc> | 2023-05-13 22:06:17 +0530 |
commit | 563cea897121b33cc5e98dc6ed3a36eb39d52766 (patch) | |
tree | 8da51d24daf9796c3d5351f13a068fc03fe997aa /7.5/op.c | |
parent | e0b9da43b6311aa4413d030b27c6cdab000aeafd (diff) |
7.5: initial commit, 4.10 with scanf instead of getchar
Diffstat (limited to '7.5/op.c')
-rw-r--r-- | 7.5/op.c | 32 |
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; +} |