Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include "rpn.h"
- int main(int argc, char **argv) {
- FILE *fp = fopen("test.txt", "rb"), *myStream;
- if (argc == 1) myStream = fp;
- else myStream = stdin;
- char line[80];
- while (fgets(line, 80, myStream)) {
- strtok(line, "\n");
- int off, pos = 0;
- double tmp;
- while (line[pos]) {
- if (isdigit(line[pos])) {
- sscanf(line + pos, "%lf%n", &tmp, &off);
- pos += off;
- push(tmp);
- } else {
- perform(line[pos]);
- sscanf(line + pos, "%*c%n", &off);
- pos += off;
- }
- }
- printf("The result is %lf\n", pop());
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement