Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- void code(FILE *in, FILE *out){
- unsigned int clen = 1;
- int c, e;
- e = fgetc(in);
- c = e;
- while (!feof(in)) {
- e = fgetc(in);
- if ((e == c) && (clen < 255)){
- clen++;
- }
- else {
- if (clen == 1){
- fputc(c,out);
- }
- else {
- fputc(c, out);
- fputc(c, out);
- fputc(clen-2, out);
- }
- clen = 1;
- }
- c = e;
- }
- }
- void decode(FILE *in, FILE *out){
- int c, e,x;
- x = 1;
- e = fgetc(in);
- c = e;
- unsigned int clen;
- while (!feof(in)) {
- e = fgetc(in);
- if ((x < 2) && (e == c)){
- x++;
- continue;
- }
- else {
- if (x == 1){
- fputc(c, out);
- continue;
- }
- else{
- clen = e;
- fputc(c,out);
- fputc(c, out);
- for (int i = 1; i <= clen; i++){
- fputc(c, out);
- }
- e = fgetc(in);
- }
- }
- c = e;
- x = 1;
- }
- }
- int main() {
- FILE *f1 = fopen("input.txt", "r");
- FILE *f2 = fopen("output.txt", "r");
- FILE *f3 = fopen("output2.txt", "w");
- //code(f1,f2);
- decode(f2,f3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement