为什么我的这个字典没法初始化
这是一个LZW算法
#define DIC_SIZE 1125#define TRUE 1#define FALSE 0#define END NULL#include <stdio.h>#include <string.h>#include <stdlib.h>typedef struct dictionary{ char *character; int code;}DIC;DIC string_tab[DIC_SIZE];int count=0;DIC *isFindDic(char *buffer);DIC *findInDic(char *prefix);char *toString(char c);//初始化字典函数void initDic(){ int i; char ch=1; for(i=0;i<255;i++){ //sprintf(&ch,"%c",i+1); string_tab[i].character=toString(i+1); string_tab[i].code=i+1; //printf("%s ",string_tab[i].character); //printf("%d\n",string_tab[i].code); count++; } string_tab[i+1].character=END;}/*字符转换为字符串 * */char *toString(char c){ char buffStr[10]; buffStr[0]=c; buffStr[1]='\0'; return buffStr;}//压缩函数 void compression(char inFileName[20],char outFileName[20]){ //char *prefix,*suffix; FILE *inFile,*outFile; char *buffer; //malloc int i; char *prefix,*suffix; //int cIsInDic=TRUE; DIC *curBuffer; if(!(inFile=fopen(inFileName,"r"))){ printf("源文件打开失败!\n"); return; } if(!(outFile=fopen(outFileName,"w"))){ printf("目标文件建立失败!\n"); return; } prefix=(char *)malloc(100); suffix=(char *)malloc(100); //prefix=fgetc(inFile); //suffix=fgetc(inFile); fgets(prefix,2,inFile); fgets(suffix,2,inFile); while(!feof(inFile)) { strcpy(buffer,prefix); strcat(buffer,suffix); if(curBuffer=isFindDic(buffer)){ fputc(curBuffer->code,outFile); prefix=buffer; fgets(suffix,2,inFile); } else{ string_tab[count].character=buffer; string_tab[count].code=count; string_tab[++count].character=END; curBuffer=findInDic(prefix); fputc(curBuffer->code,outFile); prefix=suffix; fgets(suffix,2,inFile); } } free(prefix); free(suffix); fclose(inFile); fclose(outFile);}/*查找函数1 *判断当前字串是否存在于字典当中 *若存在返回结构体指针,若不存在返回FALSE */DIC *isFindDic(char *buffer){ int i=0; DIC *curBuffer; while(END!=string_tab[i].character){ if(string_tab[i].character==buffer){ curBuffer=&string_tab[i]; return curBuffer; } i++; } return FALSE;}/*查找函数2*/DIC *findInDic(char *prefix){ int i=0; DIC *curBuffer; while(END!=string_tab[i].character){ if(string_tab[i].character==prefix){ curBuffer=&string_tab[i]; return curBuffer; } i++; } }int main(int argc, char *argv[]){ char inFileName[20],outFileName[20]; initDic(); gets(inFileName); gets(outFileName); compression(inFileName,outFileName); //free(character) return 0;}