Advertisement
JennyMcJenster

Basic file read interpreter for "Poop"

Jul 5th, 2016
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3. #include <fstream>
  4.  
  5. // https://esolangs.org/wiki/Poop
  6.  
  7. int main(int argc, const char* argv)
  8. {
  9.     const char* filename = "test.poop";
  10.  
  11.     std::ifstream file(filename);
  12.     std::string word;
  13.    
  14.     char* paper = "0123456789abcdefghijklmnopqrstuvwxyz.,-!?+*<>#@$€§%&/()[]";
  15.     char* wipes = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ.,-!?+*<>#@$€§%&/()[]";
  16.     short sheet = 0;
  17. #define PAPERLEN 57
  18.    
  19.     std::string smell = "";
  20.  
  21.     if(file.is_open())
  22.     {
  23.         while(file >> word)
  24.         {
  25.             if(word == "eat")
  26.             {
  27.                 ++sheet;
  28.                 if(sheet > PAPERLEN)
  29.                     sheet -= PAPERLEN;
  30.             }
  31.             else if(word == "puke")
  32.             {
  33.                 --sheet;
  34.                 if(sheet < 0)
  35.                     sheet += PAPERLEN;
  36.             }
  37.             else if(word == "poop")
  38.             {
  39.                 char outchar = *(paper + sheet*sizeof(char));
  40.                 smell += outchar;
  41.             }
  42.             else if(word == "POOP")
  43.             {
  44.                 char outchar = *(wipes + sheet*sizeof(char));
  45.                 smell += outchar;
  46.             }
  47.             else if(word == "sniff")
  48.             {
  49.                 std::cout << smell << std::endl;
  50.             }
  51.             else if(word == "flush")
  52.             {
  53.                 smell = "";
  54.                 sheet = 0;
  55.             }
  56.             else if(word == "fart") // Added my own keyword for inserting a space character
  57.             {
  58.                 char outchar = ' ';
  59.                 smell += outchar;
  60.             }
  61.             else
  62.             {
  63.                 std::cout << "[ERROR] Word \"" << word << "\" has no function." << std::endl;
  64.             }
  65.         }
  66.     }
  67.  
  68.     system("pause");
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement