c语言压缩包怎样改成中文

c语言压缩包怎样改成中文,第1张

1、首先,需要利用C语言的宏。

2、其次,将一些常见的英文表达。

3、然后,通过define,转化为中文。压缩包就是将初始文件经过压缩形成的文件,压缩文件内存更小,可以将多个文件压缩成一个文件。

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

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

   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

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/8045745.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-12
下一篇 2023-04-12

发表评论

登录后才能评论

评论列表(0条)

保存