Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include "rpn.h"
  6.  
  7. int main(int argc, char **argv) {
  8.     FILE *fp = fopen("test.txt", "rb"), *myStream;
  9.     if (argc == 1) myStream = fp;
  10.     else myStream = stdin;
  11.     char line[80];
  12.     while (fgets(line, 80, myStream)) {
  13.         strtok(line, "\n");
  14.         int off, pos = 0;
  15.         double tmp;
  16.         while (line[pos]) {
  17.             if (isdigit(line[pos])) {
  18.                 sscanf(line + pos, "%lf%n", &tmp, &off);
  19.                 pos += off;
  20.                 push(tmp);
  21.             } else {
  22.                 perform(line[pos]);
  23.                 sscanf(line + pos, "%*c%n", &off);
  24.                 pos += off;
  25.             }
  26.         }
  27.         printf("The result is %lf\n", pop());
  28.     }
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement