Last active
August 29, 2015 14:16
-
-
Save tjb0607/69038a4ff74cb9b27051 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
char* EncodedPrint(char* string) | |
{ | |
int i = 0; | |
while (string[i] != '\0') | |
{ | |
switch (string[i]) | |
{ | |
case '\\': | |
cout << "\\\\"; | |
break; | |
case '\n': | |
cout << "\\n"; | |
break; | |
case '\t': | |
cout << "\\t"; | |
break; | |
case '\"': | |
cout << "\\\""; | |
break; | |
default: | |
cout << string[i]; | |
break; | |
} | |
i++; | |
} | |
return string + i + 1; | |
} | |
int main() | |
{ | |
char quine[] = "#include <iostream>\nusing namespace std;\n\nchar* EncodedPrint(char* string)\n{\n\tint i = 0;\n\twhile (string[i] != '\\0')\n\t{\n\t\tswitch (string[i])\n\t\t{\n\t\tcase '\\\\':\n\t\t\tcout << \"\\\\\\\\\";\n\t\t\tbreak;\n\t\tcase '\\n':\n\t\t\tcout << \"\\\\n\";\n\t\t\tbreak;\n\t\tcase '\\t':\n\t\t\tcout << \"\\\\t\";\n\t\t\tbreak;\n\t\tcase '\\\"':\n\t\t\tcout << \"\\\\\\\"\";\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tcout << string[i];\n\t\t\tbreak;\n\t\t}\n\t\ti++;\n\t}\n\treturn string + i + 1;\n}\n\nint main()\n{\n\tchar quine[] = \"\0\";\n\n\tcout << quine;\n\tchar* rest = EncodedPrint(quine);\n\tcout << \"\\\\0\";\n\tEncodedPrint(rest);\n\tcout << rest;\n}\n"; | |
cout << quine; | |
char* rest = EncodedPrint(quine); | |
cout << "\\0"; | |
EncodedPrint(rest); | |
cout << rest; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment