Linksys backup format to text convertor


/ Published in: C++
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4.  
  5. int decode(unsigned char);
  6.  
  7. int decode(unsigned char ch) {
  8. ch = ~((ch << 2) | ((ch & 0xC0) >> 6));
  9. if (ch) {
  10. if (isprint(ch)) {
  11. return ch;
  12. } else {
  13. return ' ';
  14. }
  15. }
  16. return '\n';
  17. }
  18.  
  19. int main(int argc, char *argv[]) {
  20. int ch;
  21. FILE *fp;
  22.  
  23. if (argc < 2) {
  24. fp = stdin;
  25. } else {
  26. if (NULL == (fp = fopen(argv[1], "r"))) {
  27. fprintf(stderr, "Error: Cannot open file %s\n", argv[1]);
  28. exit(EXIT_FAILURE);
  29. }
  30. }
  31.  
  32. while (EOF != (ch =fgetc(fp))) {
  33. fputc(decode(ch), stdout);
  34. }
  35. return EXIT_SUCCESS;
  36. }
  37.  

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.