/ Published in: C++
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#include <stdio.h> #include <stdlib.h> #include <ctype.h> int decode(unsigned char); int decode(unsigned char ch) { ch = ~((ch << 2) | ((ch & 0xC0) >> 6)); if (ch) { if (isprint(ch)) { return ch; } else { return ' '; } } return '\n'; } int main(int argc, char *argv[]) { int ch; FILE *fp; if (argc < 2) { fp = stdin; } else { if (NULL == (fp = fopen(argv[1], "r"))) { fprintf(stderr, "Error: Cannot open file %s\n", argv[1]); exit(EXIT_FAILURE); } } while (EOF != (ch =fgetc(fp))) { fputc(decode(ch), stdout); } return EXIT_SUCCESS; }