C Data Compression

0

I need to implement a C program that creates files from text files (for example, C program source code, among others). This compression will be performed using the Run Length Encoding compression method. The program should have a menu with 3 options, as below:

1 - Compression - > writes a new file with compressed data 2 - Undo compression - > writes a new file with the uncompressed data 3 - Exit

I need help

Start a little below, but much is missing.

 #include<stdio.h>
 #include<stdlib.h>
 #include<string.h>

 int main(int argc, char *argv[]){

 int op;
 char conteudo[1110];
 FILE *pf;
 long tamanho;

do{

    system("cls");
 printf("#######################################################\n");
    printf("       |   Escolha a opcao desejada            |\n");
    printf("       | 1 - Fazer Compressao.                 |\n");
    printf("       | 2 - Desfazer a compressao             |\n");
    printf("       | 3 - Sair                              |\n");

  printf("############################################################\n");

    printf("Informe a opcao desejada: ");
    scanf("%d", &op);

    if(op != 3){
        switch(op){
            case 1:
                    pf = fopen("teste.txt", "r");

                    if(pf == NULL){
                        printf("ERRO!!");
                        getch();
                    }else{
                        fseek(pf, 0, SEEK_END);
                        tamanho = ftell(pf);
                        printf("O arquivo possui %ld bytes", tamanho);
                        getch();
                    }

                break;
            case 2:

                if(pf == NULL){
                    printf("Não foi possível abrir arquivo");
                }else{
                    fseek(pf, 0, SEEK_END);
                    tamanho = ftell(pf);

                    pf = fopen("teste.txt", "rb");
                    fread(&conteudo, sizeof(char), 1110, pf);
                    printf("\n%s", conteudo);
                    getch();
                }
                break;
            default:
                printf("Opcao invalida!\n\n\n");
                getch();
        }
    }

}while(op != 3);
fclose(pf);
}

The text txt file can be something like wwwwwwwwwwwwrrrrrrrrrrrrrrrrrttttttttttttttttttttttttyyyyyyyyyyyyyyyyyyyyyyyyyrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr999999999999999999997777777

    
asked by anonymous 21.11.2017 / 00:55

0 answers