Advertisement
Guest User

Untitled

a guest
May 20th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. void code(FILE *in, FILE *out){
  6. unsigned int clen = 1;
  7. int c, e;
  8. e = fgetc(in);
  9. c = e;
  10. while (!feof(in)) {
  11. e = fgetc(in);
  12. if ((e == c) && (clen < 255)){
  13. clen++;
  14. }
  15. else {
  16. if (clen == 1){
  17. fputc(c,out);
  18. }
  19. else {
  20. fputc(c, out);
  21. fputc(c, out);
  22. fputc(clen-2, out);
  23. }
  24. clen = 1;
  25. }
  26. c = e;
  27.  
  28. }
  29. }
  30.  
  31. void decode(FILE *in, FILE *out){
  32. int c, e,x;
  33. x = 1;
  34. e = fgetc(in);
  35. c = e;
  36. unsigned int clen;
  37. while (!feof(in)) {
  38. e = fgetc(in);
  39. if ((x < 2) && (e == c)){
  40. x++;
  41. continue;
  42. }
  43. else {
  44. if (x == 1){
  45. fputc(c, out);
  46. continue;
  47. }
  48. else{
  49. clen = e;
  50. fputc(c,out);
  51. fputc(c, out);
  52. for (int i = 1; i <= clen; i++){
  53. fputc(c, out);
  54. }
  55. e = fgetc(in);
  56. }
  57. }
  58. c = e;
  59. x = 1;
  60. }
  61. }
  62.  
  63. int main() {
  64. FILE *f1 = fopen("input.txt", "r");
  65. FILE *f2 = fopen("output.txt", "r");
  66. FILE *f3 = fopen("output2.txt", "w");
  67. //code(f1,f2);
  68. decode(f2,f3);
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement