如何用c语言压缩解压文件夹

Python089

如何用c语言压缩解压文件夹,第1张

压缩是一种有效的减小数据量的方法,目前已经被广泛应用于各种类型的信息系统之中。

   一种压缩文本文件的方法如下:

   1. 原始文本文件中的非字母的字符,直接拷贝到压缩文件中;

   2.

原始文件中的词(全部由字母组成),如果是第一次出现,则将该词加入到一个词的列表中,并拷贝到压缩文件中;否则该词不拷贝到压缩文件中,而是将该词在词的列表中的位置拷贝到压缩文件中。

   3. 词的列表的起始位置为 1 。 词的定义为文本中由大小写字母组成的最大序列。大写字母和小写字母认为是不同的字母,即 abc 和 Abc

是不同的词。词的例子如下: * x-ray 包括两个词 x 和 ray * mary's 包括两个词 mary 和 s * a c-Dec 包括三个词 a 和

c 和 Dec 编写一个程序,输入为一组字符串,输出为压缩后的文本。

输入:

   输入为一段文本,你可以假设输入中不会出现数字、每行的长度不会超过 80 个字符,并且输入文本的大小不会超过 10M。

输出:

压缩后的文本。

输入:

Please, please do it--it would please Mary very,

very much.

Thanks

输出:

Please, please do it--4 would 2 Mary very,

7 much.

Thanks

#include <stdlib.h>

#include <stdio.h>

#include <string.h>

#define LEN 1<<20

int isArabic(char c){

    return ('a'<=c&&c<='z') || ('A'<=c&&c<='Z')

}

int main()

{

    char dict[LEN]

    char *index[100000]

    char buf[82]

    int nWord=0

    int i,j

    char c

    char *inFile="G:\\in.txt",*outFile="G:\\out.txt"

    FILE *inp,*outp

     

    if((inp=fopen(inFile,"r"))==NULL){

      printf("cannot open\n")

      exit(1)

    }

    if((outp=fopen(outFile,"w"))==NULL){

      printf("out fail\n")

    }

    index[0]=dict

    do{

        /* get a word */

        i=0

        do{

            c=fgetc(inp)

            buf[i++]=c 

        }while(isArabic(c))

         

        buf[i-1]=0

        /* put it to dict */

        if(i>1){

            for(j=0j<nWordj++){

              if(strcmp(index[j],buf)==0){

                break

              }

            }

            if(j==nWord){

              strcpy(index[nWord],buf)

              index[nWord+1]=index[nWord]+strlen(buf)+1

              nWord++

/*              printf("new: %s\n",buf)*/

            }else{

              sprintf(buf,"%d",j+1)

/*              printf("found: %s\n",buf)*/

            }

        }

        /* put it to output file */

        if(c!=EOF)

          fprintf(outp,"%s%c",buf,c)

        else

          fprintf(outp,"%s",buf)

    }while(c!=EOF)

     

    fclose(inp)

    fclose(outp)

/*    system("PAUSE")*/

    return EXIT_SUCCESS

}

winrar有个命令行解压

rar.exe -y x -p密码 "c:\test.rar" "d:\"

只需要在C语言里把要爆破用的密码生成或者从别的字典导入

然后拼接成命令循环执行就好了

简单一点的 直接调用系统命令

比如system("unzip ___filename___ -d target_path")

这样做 实际就相当于在命令行下敲了这样的一个命令

不过 这个要求系统内 必须安装了unzip这个软件 即支持这个命令

复杂一些的 你可以再网上找一个开源的gzip 很多很好找的 然后看懂代码 调用对应的接口函数

这样做的好处不需要依赖系统环境